You are here

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

Same name and namespace in other branches
  1. 8 src/Element/Buttons.php \Drupal\select_or_other\Element\Buttons::processSelectOrOther()
  2. 4.x src/Element/Buttons.php \Drupal\select_or_other\Element\Buttons::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 Buttons::processSelectOrOther()
ElementsTest::testProcessSelectOrOther in Tests/src/Unit/ElementsTest.php
Tests the processing of a select or other element.

File

src/Element/Buttons.php, line 26
Contains Drupal\select_or_other\Element\Buttons.

Class

Buttons
Provides a form element with buttons and other option.

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);
  if (!$element['#multiple']) {
    $element['select']['#type'] = 'radios';
    $element['other']['#states'] = ElementBase::prepareStates('visible', $element['#name'] . '[select]', 'value', 'select_or_other');
  }
  else {
    $element['select']['#type'] = 'checkboxes';
    $element['other']['#states'] = ElementBase::prepareStates('visible', $element['#name'] . '[select][select_or_other]', 'checked', TRUE);
  }
  return $element;
}