You are here

public static function DropdownWidgetType::validateElement in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::validateElement()
  2. 8.2 modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::validateElement()
  3. 8.3 modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::validateElement()
  4. 8.4 modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::validateElement()
  5. 8.5 modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::validateElement()
  6. 8.6 modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::validateElement()
  7. 8.7 modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::validateElement()
  8. 8.8 modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::validateElement()
  9. 10.3.x modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::validateElement()
  10. 10.0.x modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::validateElement()
  11. 10.1.x modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::validateElement()
  12. 10.2.x modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php \Drupal\dropdown\Plugin\Field\FieldWidget\DropdownWidgetType::validateElement()

Form validation handler for widget elements.

Parameters

array $element: The form element.

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

File

modules/custom/dropdown/src/Plugin/Field/FieldWidget/DropdownWidgetType.php, line 129

Class

DropdownWidgetType
Plugin implementation of the 'dropdown_widget_type' widget.

Namespace

Drupal\dropdown\Plugin\Field\FieldWidget

Code

public static function validateElement(array $element, FormStateInterface $form_state) {
  if ($element['#required'] && $element['#value'] == '_none') {
    $form_state
      ->setError($element, t('@name field is required.', [
      '@name' => $element['#title'],
    ]));
  }

  // Save the value in the element key_column.
  // Note: there is only one item because the field is not multiple value.
  $items = [
    $element['#key_column'] => $element['#value'],
  ];
  $form_state
    ->setValueForElement($element, $items);
}