You are here

protected static function WebformMultiple::initializeElement in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Element/WebformMultiple.php \Drupal\webform\Element\WebformMultiple::initializeElement()

Initialize element.

Parameters

array $element: The element.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

array $complete_form: An associative array containing the structure of the form.

1 call to WebformMultiple::initializeElement()
WebformMultiple::processWebformMultiple in src/Element/WebformMultiple.php
Process items and build multiple elements widget.

File

src/Element/WebformMultiple.php, line 312

Class

WebformMultiple
Provides a webform element to assist in creation of multiple elements.

Namespace

Drupal\webform\Element

Code

protected static function initializeElement(array &$element, FormStateInterface $form_state, array &$complete_form) {

  // Track element child keys.
  $element['#child_keys'] = Element::children($element['#element']);
  if (!$element['#child_keys']) {

    // Apply multiple element's required/optional #states to the
    // individual element.
    if (isset($element['#_webform_states'])) {
      $element['#element'] += [
        '#states' => [],
      ];
      $element['#element']['#states'] = array_intersect_key(WebformElementHelper::getStates($element), [
        'required' => 'required',
        'optional' => 'optional',
      ]);
    }
  }
  else {

    // Initialize, prepare, and finalize composite sub-elements.
    // Get composite element required/options states from visible/hidden states.
    $required_states = WebformElementHelper::getRequiredFromVisibleStates($element);
    static::initializeElementRecursive($element, $form_state, $complete_form, $element['#element'], $required_states);
  }
}