You are here

protected function WebformEntitySettingsBaseForm::appendBehaviors in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/EntitySettings/WebformEntitySettingsBaseForm.php \Drupal\webform\EntitySettings\WebformEntitySettingsBaseForm::appendBehaviors()

Append behavior checkboxes to element.

Parameters

array $element: An array of form elements.

array $behavior_elements: An associative array of behavior elements.

array $settings: The webform's settings.

array $default_settings: The global webform default settings.

3 calls to WebformEntitySettingsBaseForm::appendBehaviors()
WebformEntitySettingsFormForm::form in src/EntitySettings/WebformEntitySettingsFormForm.php
Gets the actual form array to be built.
WebformEntitySettingsGeneralForm::form in src/EntitySettings/WebformEntitySettingsGeneralForm.php
Gets the actual form array to be built.
WebformEntitySettingsSubmissionsForm::form in src/EntitySettings/WebformEntitySettingsSubmissionsForm.php
Gets the actual form array to be built.

File

src/EntitySettings/WebformEntitySettingsBaseForm.php, line 129

Class

WebformEntitySettingsBaseForm
Base webform entity settings form.

Namespace

Drupal\webform\EntitySettings

Code

protected function appendBehaviors(array &$element, array $behavior_elements, array $settings, array $default_settings) {
  $weight = 0;
  foreach ($behavior_elements as $behavior_key => $behavior_element) {
    $behavior_element += [
      'states' => [],
    ];

    // Add group.
    if (isset($behavior_element['group'])) {
      $group = (string) $behavior_element['group'];
      if (!isset($element[$group])) {
        $element[$group] = [
          '#type' => 'container',
          '#prefix' => '<strong>',
          '#suffix' => '</strong>',
          '#markup' => $group,
          '#weight' => $weight,
        ];
        $weight += 10;
      }
    }

    // Add behavior checkbox.
    if (!empty($default_settings['default_' . $behavior_key])) {
      $element[$behavior_key . '_disabled'] = [
        '#type' => 'checkbox',
        '#title' => $behavior_element['title'],
        '#description' => $behavior_element['all_description'],
        '#states' => $behavior_element['states'],
        '#disabled' => TRUE,
        '#default_value' => TRUE,
        '#weight' => $weight,
      ];
      $element[$behavior_key] = [
        '#type' => 'value',
        '#value' => $settings[$behavior_key],
      ];
      if (isset($behavior_element['access'])) {
        $element[$behavior_key . '_disabled']['#access'] = $behavior_element['access'];
      }
    }
    else {
      $element[$behavior_key] = [
        '#type' => 'checkbox',
        '#title' => $behavior_element['title'],
        '#description' => $behavior_element['form_description'],
        '#states' => $behavior_element['states'],
        '#return_value' => TRUE,
        '#default_value' => $settings[$behavior_key],
        '#weight' => $weight,
      ];
      if (isset($behavior_element['access'])) {
        $element[$behavior_key]['#access'] = $behavior_element['access'];
      }
    }
    $weight += 10;
  }
}