You are here

public function GeolocationHTML5Widget::flagErrors in Geolocation Field 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/Field/FieldWidget/GeolocationHTML5Widget.php \Drupal\geolocation\Plugin\Field\FieldWidget\GeolocationHTML5Widget::flagErrors()
  2. 8.2 src/Plugin/Field/FieldWidget/GeolocationHTML5Widget.php \Drupal\geolocation\Plugin\Field\FieldWidget\GeolocationHTML5Widget::flagErrors()

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/GeolocationHTML5Widget.php, line 26

Class

GeolocationHTML5Widget
Plugin implementation of the 'geolocation_html5' widget.

Namespace

Drupal\geolocation\Plugin\Field\FieldWidget

Code

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 could be determined for required field %field.', [
        '%field' => $items
          ->getFieldDefinition()
          ->getLabel(),
      ]));
    }
  }
  parent::flagErrors($items, $violations, $form, $form_state);
}