You are here

public static function WebformEntitySelect::processSelect in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Element/WebformEntitySelect.php \Drupal\webform\Element\WebformEntitySelect::processSelect()

Processes a select list form element.

This process callback is mandatory for select fields, since all user agents automatically preselect the first available option of single (non-multiple) select lists.

Parameters

array $element: The form element to process.

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

array $complete_form: The complete form structure.

Return value

array The processed element.

Overrides Select::processSelect

See also

_form_validate()

File

src/Element/WebformEntitySelect.php, line 20

Class

WebformEntitySelect
Provides a webform element for a entity select menu.

Namespace

Drupal\webform\Element

Code

public static function processSelect(&$element, FormStateInterface $form_state, &$complete_form) {
  static::setOptions($element);
  $element = parent::processSelect($element, $form_state, $complete_form);

  // Must convert this element['#type'] to a 'select' to prevent
  // "Illegal choice %choice in %name element" validation error.
  // @see \Drupal\Core\Form\FormValidator::performRequiredValidation
  $element['#type'] = 'select';

  // Add class.
  $element['#attributes']['class'][] = 'webform-entity-select';
  return $element;
}