You are here

protected static function Buttons::ensureCorrectDefaultValue in Select (or other) 8

Same name and namespace in other branches
  1. 4.x src/Element/Buttons.php \Drupal\select_or_other\Element\Buttons::ensureCorrectDefaultValue()

Ensures the element has the correct default value.

Parameters

array $element: The select or other element.

1 call to Buttons::ensureCorrectDefaultValue()
Buttons::setSelectType in src/Element/Buttons.php
Sets the type of buttons to use for the select element.

File

src/Element/Buttons.php, line 51

Class

Buttons
Provides a form element with buttons and other option.

Namespace

Drupal\select_or_other\Element

Code

protected static function ensureCorrectDefaultValue(array &$element) {
  if ($element['select']['#type'] === 'radios') {

    // Radio buttons do not accept an array as default value.
    if (!empty($element['select']['#default_value']) && is_array($element['select']['#default_value'])) {
      $element['select']['#default_value'] = reset($element['select']['#default_value']);
    }
  }
}