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);
  }
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);
  }
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 ) ; }
Form validation handler for widget elements.

@param array $element
The form element.
@param \Drupal\Core\Form\FormStateInterface $form_state
The form state.
Form validation handler for widget elements .