You are here

public static function OptionsBase::processOptionsProperties in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/WebformElement/OptionsBase.php \Drupal\webform\Plugin\WebformElement\OptionsBase::processOptionsProperties()

Processes options (custom) properties.

File

src/Plugin/WebformElement/OptionsBase.php, line 259

Class

OptionsBase
Provides a base 'options' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public static function processOptionsProperties(&$element, FormStateInterface $form_state, &$complete_form) {
  if (empty($element['#options__properties'])) {
    return $element;
  }
  foreach ($element['#options__properties'] as $option_key => $options__properties) {
    if (!isset($element[$option_key]) || !is_array($options__properties)) {
      continue;
    }

    // Remove ignored properties.
    $options__properties = WebformElementHelper::removeIgnoredProperties($options__properties);
    foreach ($options__properties as $property => $value) {
      $option_element =& $element[$option_key];
      if (in_array($property, [
        '#attributes',
        '#wrapper_attributes',
        '#label_attributes',
      ])) {

        // Apply attributes.
        $option_element += [
          $property => [],
        ];
        foreach ($value as $attribute_name => $attribute_value) {

          // Merge attributes class.
          if ($attribute_name === 'class' && isset($element[$option_key][$property][$attribute_name])) {
            $option_element[$property][$attribute_name] = array_merge($element[$option_key][$property][$attribute_name], $attribute_value);
          }
          else {
            $option_element[$property][$attribute_name] = $attribute_value;
          }
        }
      }
      else {
        $option_element[$property] = $value;
      }
    }
  }
  return $element;
}