You are here

public function OptionsBase::setDefaultValue in YAML Form 8

Set an element's default value using saved data.

Parameters

array $element: An element.

Overrides YamlFormElementBase::setDefaultValue

File

src/Plugin/YamlFormElement/OptionsBase.php, line 140

Class

OptionsBase
Provides a base 'options' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function setDefaultValue(array &$element) {
  if (!isset($element['#default_value'])) {
    return;
  }

  // Compensate for #default_value not being an array, for elements that
  // allow for multiple #options to be selected/checked.
  if ($this
    ->hasMultipleValues($element) && !is_array($element['#default_value'])) {
    $element['#default_value'] = [
      $element['#default_value'],
    ];
  }
}