You are here

public function Checkboxes::initialize in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/Checkboxes.php \Drupal\webform\Plugin\WebformElement\Checkboxes::initialize()

Initialize an element to be displayed, rendered, or exported.

Parameters

array $element: An element.

Overrides WebformElementBase::initialize

File

src/Plugin/WebformElement/Checkboxes.php, line 73

Class

Checkboxes
Provides a 'checkboxes' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function initialize(array &$element) {
  parent::initialize($element);
  $option_types = [
    'options_all',
    'options_none',
  ];
  foreach ($option_types as $option_type) {
    if (!empty($element['#' . $option_type])) {
      $element['#' . $option_type . '_value'] = $this
        ->getElementProperty($element, $option_type . '_value');
      $element['#' . $option_type . '_text'] = $this
        ->getElementProperty($element, $option_type . '_text');

      // Set #options for every element except 'webform_entity_checkboxes'.
      // @see \Drupal\webform\Plugin\WebformElement\WebformEntityReferenceTrait::setOptions
      if ($element['#type'] !== 'webform_entity_checkboxes') {
        $element['#options'][$element['#' . $option_type . '_value']] = $element['#' . $option_type . '_text'];
      }
    }
  }
}