public function GeolocationGooglegeocoderWidget::flagErrors in Geolocation Field 8
Reports field-level validation errors against actual form elements.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The field values.
\Symfony\Component\Validator\ConstraintViolationListInterface $violations: A list of constraint violations to flag.
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 form state.
Overrides WidgetBase::flagErrors
File
- src/
Plugin/ Field/ FieldWidget/ GeolocationGooglegeocoderWidget.php, line 89
Class
- GeolocationGooglegeocoderWidget
- Plugin implementation of the 'geolocation_googlegeocoder' widget.
Namespace
Drupal\geolocation\Plugin\Field\FieldWidgetCode
public function flagErrors(FieldItemListInterface $items, ConstraintViolationListInterface $violations, array $form, FormStateInterface $form_state) {
foreach ($violations as $violation) {
if ($violation
->getMessageTemplate() == 'This value should not be null.') {
$form_state
->setErrorByName($items
->getName(), $this
->t('No location has been selected yet for required field %field.', [
'%field' => $items
->getFieldDefinition()
->getLabel(),
]));
}
}
parent::flagErrors($items, $violations, $form, $form_state);
}