You are here

public static function IssueWidget::validateElement in Simplenews 8.2

Same name and namespace in other branches
  1. 3.x src/Plugin/Field/FieldWidget/IssueWidget.php \Drupal\simplenews\Plugin\Field\FieldWidget\IssueWidget::validateElement()

Form validation handler for widget elements.

Parameters

array $element: The form element.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

Overrides OptionsWidgetBase::validateElement

File

src/Plugin/Field/FieldWidget/IssueWidget.php, line 150

Class

IssueWidget
Plugin implementation of the 'simplenews_issue' widget.

Namespace

Drupal\simplenews\Plugin\Field\FieldWidget

Code

public static function validateElement(array $element, FormStateInterface $form_state) {

  // OptionsWidgetBase uses '_none' as a special value.
  if ($element['#value'] == '_none') {
    if ($element['#required']) {
      $form_state
        ->setError($element, t('@name field is required.', [
        '@name' => $element['#title'],
      ]));
    }
    else {
      $form_state
        ->setValueForElement($element, NULL);
    }
  }
}