public function EntityReferenceBrowserWidget::errorElement in Entity Browser 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldWidget/EntityReferenceBrowserWidget.php \Drupal\entity_browser\Plugin\Field\FieldWidget\EntityReferenceBrowserWidget::errorElement()
Assigns a field-level validation error to the right widget sub-element.
Depending on the widget's internal structure, a field-level validation error needs to be flagged on the right sub-element.
Parameters
array $element: An array containing the form element for the widget, as generated by formElement().
\Symfony\Component\Validator\ConstraintViolationInterface $violation: A constraint violation reported during the validation phase.
array $form: The form structure where field elements are attached to. This might be a full form structure, or a sub-element of a larger form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array|bool The element on which the error should be flagged, or FALSE to completely ignore the violation (use with care!).
Overrides WidgetBase::errorElement
File
- src/
Plugin/ Field/ FieldWidget/ EntityReferenceBrowserWidget.php, line 513
Class
- EntityReferenceBrowserWidget
- Plugin implementation of the 'entity_reference' widget for entity browser.
Namespace
Drupal\entity_browser\Plugin\Field\FieldWidgetCode
public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, FormStateInterface $form_state) {
if ($trigger = $form_state
->getTriggeringElement()) {
// Can be triggered by "Remove" button.
if (end($trigger['#parents']) === 'remove_button') {
return FALSE;
}
}
return parent::errorElement($element, $violation, $form, $form_state);
}