當前位置: 首頁>>代碼示例>>PHP>>正文


PHP FormStateInterface::getError方法代碼示例

本文整理匯總了PHP中Drupal\Core\Form\FormStateInterface::getError方法的典型用法代碼示例。如果您正苦於以下問題:PHP FormStateInterface::getError方法的具體用法?PHP FormStateInterface::getError怎麽用?PHP FormStateInterface::getError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\Core\Form\FormStateInterface的用法示例。


在下文中一共展示了FormStateInterface::getError方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getError

 /**
  * Returns the error message filed against the given form element.
  *
  * Form errors higher up in the form structure override deeper errors as well
  * as errors on the element itself.
  *
  * @return string|null
  *   Either the error message for this element or NULL if there are no errors.
  *
  * @throws \BadMethodCallException
  *   When the element instance was not constructed with a valid form state
  *   object.
  */
 public function getError()
 {
     if (!$this->formState) {
         throw new \BadMethodCallException('The element instance must be constructed with a valid form state object to use this method.');
     }
     return $this->formState->getError($this->array);
 }
開發者ID:Suite5,項目名稱:feelmybook,代碼行數:20,代碼來源:Element.php

示例2: testGetError

 /**
  * @covers ::getError
  */
 public function testGetError()
 {
     $element = ['#foo' => 'bar'];
     $message = 'bar';
     $this->decoratedFormState->getError($element)->willReturn($message)->shouldBeCalled();
     $this->assertSame($message, $this->formStateDecoratorBase->getError($element));
 }
開發者ID:eigentor,項目名稱:tommiblog,代碼行數:10,代碼來源:FormStateDecoratorBaseTest.php

示例3: getError

 /**
  * {@inheritdoc}
  */
 public function getError(array $element)
 {
     return $this->mainFormState->getError($element);
 }
開發者ID:Laudanum,項目名稱:authorization,代碼行數:7,代碼來源:SubFormState.php

示例4: validateDatelist

 /**
  * Validation callback for a datelist element.
  *
  * If the date is valid, the date object created from the user input is set in
  * the form for use by the caller. The work of compiling the user input back
  * into a date object is handled by the value callback, so we can use it here.
  * We also have the raw input available for validation testing.
  *
  * @param array $element
  *   The element being processed.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  * @param array $complete_form
  *   The complete form structure.
  */
 public static function validateDatelist(&$element, FormStateInterface $form_state, &$complete_form)
 {
     $input_exists = FALSE;
     $input = NestedArray::getValue($form_state->getValues(), $element['#parents'], $input_exists);
     if ($input_exists) {
         $all_empty = static::checkEmptyInputs($input, $element['#date_part_order']);
         // If there's empty input and the field is not required, set it to empty.
         if (empty($input['year']) && empty($input['month']) && empty($input['day']) && !$element['#required']) {
             $form_state->setValueForElement($element, NULL);
         } elseif (empty($input['year']) && empty($input['month']) && empty($input['day']) && $element['#required']) {
             $form_state->setError($element, t('The %field date is required.'));
         } elseif (!empty($all_empty)) {
             foreach ($all_empty as $value) {
                 $form_state->setError($element[$value], t('A value must be selected for %part.', array('%part' => $value)));
             }
         } else {
             // If the input is valid, set it.
             $date = $input['object'];
             if ($date instanceof DrupalDateTime && !$date->hasErrors()) {
                 $form_state->setValueForElement($element, $date);
             } elseif ($form_state->getError($element) === NULL) {
                 $form_state->setError($element, t('The %field date is invalid.', array('%field' => !empty($element['#title']) ? $element['#title'] : '')));
             }
         }
     }
 }
開發者ID:jthoresen,項目名稱:PladsenDrupal,代碼行數:41,代碼來源:Datelist.php


注:本文中的Drupal\Core\Form\FormStateInterface::getError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。