当前位置: 首页>>代码示例>>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;未经允许,请勿转载。