本文整理汇总了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);
}
示例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));
}
示例3: getError
/**
* {@inheritdoc}
*/
public function getError(array $element)
{
return $this->mainFormState->getError($element);
}
示例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'] : '')));
}
}
}
}