You are here

public static function Select::processSelectOrOther in Select (or other) 8.3

Same name and namespace in other branches
  1. 8 src/Element/Select.php \Drupal\select_or_other\Element\Select::processSelectOrOther()
  2. 4.x src/Element/Select.php \Drupal\select_or_other\Element\Select::processSelectOrOther()

Render API callback: Expands the select_or_other element type.

Expands the select or other element to have a 'select' and 'other' field.

Overrides ElementBase::processSelectOrOther

1 call to Select::processSelectOrOther()
ElementsTest::testProcessSelectOrOther in Tests/src/Unit/ElementsTest.php
Tests the processing of a select or other element.

File

src/Element/Select.php, line 25
Contains Drupal\select_or_other\Element\Select.

Class

Select
Provides a form element with a select box and other option. Properties:

Namespace

Drupal\select_or_other\Element

Code

public static function processSelectOrOther(&$element, FormStateInterface $form_state, &$complete_form) {
  $element = parent::processSelectOrOther($element, $form_state, $complete_form);
  $element['select']['#type'] = 'select';
  if (!$element['#multiple']) {
    $element['other']['#states'] = ElementBase::prepareStates('visible', $element['#name'] . '[select]', 'value', 'select_or_other');
  }
  else {
    $element['select']['#multiple'] = TRUE;

    // todo Drupal #states does not support multiple select elements. We have
    // to simulate #states using our own javascript until #1149078 is
    // resolved. @see https://www.drupal.org/node/1149078
    $element['select']['#attached'] = [
      'library' => [
        'select_or_other/multiple_select_states_hack',
      ],
    ];
  }
  return $element;
}