You are here

protected static function Select::addStatesHandling in Select (or other) 4.x

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

Adds a #states array to the other field to make hide/show work.

Parameters

array $element: The select or other element.

1 call to Select::addStatesHandling()
Select::processSelectOrOther in src/Element/Select.php
Render API callback: Expands the select_or_other element type.

File

src/Element/Select.php, line 60

Class

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

Namespace

Drupal\select_or_other\Element

Code

protected static function addStatesHandling(array &$element) {
  if (!$element['#multiple']) {
    $element['other']['#states'] = static::prepareState('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',
      ],
    ];
  }
}