function protected function SystemThemeSettings::createGroups

8.x-3.x SystemThemeSettings.php protected SystemThemeSettings::createGroups(Element $form, FormStateInterface $form_state)

Sets up the vertical tab groupings.

Parameters

\Drupal\bootstrap\Utility\Element $form: The Element object that comprises the form.

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

Class

SystemThemeSettings
Implements hook_form_system_theme_settings_alter().

Namespace

Drupal\bootstrap\Plugin\Form

Source src/Plugin/Form/SystemThemeSettings.php (line 50)

protected function createGroups(Element $form, FormStateInterface $form_state) {
  // Vertical tabs for global settings provided by core or contrib modules.
  if (!isset($form['global'])) {
    $form['global'] = [
      '#type' => 'vertical_tabs',
      '#weight' => -9,
      '#prefix' => '<h2><small>' . t('Override Global Settings') . '</small></h2>',
    ];
  }

  // Iterate over existing children and move appropriate ones to global group.
  foreach ($form->children() as $child) {
    if ($child->isType(['details', 'fieldset']) && !$child->hasProperty('group')) {
      $child->setProperty('type', 'details');
      $child->setProperty('group', 'global');
    }
  }

  // Provide the necessary default groups.
  $form['bootstrap'] = [
    '#type' => 'vertical_tabs',
    '#attached' => ['library' => ['bootstrap/theme-settings']],
    '#prefix' => '<h2><small>' . t('Bootstrap Settings') . '</small></h2>',
    '#weight' => -10,
  ];
  $groups = [
    'general' => t('General'),
    'components' => t('Components'),
    'javascript' => t('JavaScript'),
    'cdn' => t('CDN'),
    'advanced' => t('Advanced'),
  ];
  foreach ($groups as $group => $title) {
    $form[$group] = [
      '#type' => 'details',
      '#title' => $title,
      '#group' => 'bootstrap',
    ];

    // Show a button to reset cached HTTP requests.
    if ($group === 'advanced') {
      $cache = \Drupal::keyValueExpirable('theme:' . $this->theme->getName() . ':http');
      $count = count($cache->getAll());
      $form[$group]['reset_http_request_cache'] = [
        '#type' => 'item',
        '#title' => $this->t('Cached HTTP requests: @count', ['@count' => $count]),
        '#weight' => 100,
        '#smart_description' => FALSE,
        '#description' => $this->t('All external HTTP requests initiated by this theme are subject to caching. Cacheability is determined automatically based on a manually passed TTL value by the initiator or if there is a "max-age" response header present. These cached requests will persist through cache rebuilds and will only be requested again once they have expired. If you believe there is some request not being properly retrieved, you can manually reset this cache here.'),
        '#description_display' => 'before',
        '#prefix' => '<div id="reset-http-request-cache">',
        '#suffix' => '</div>',
      ];

      $form[$group]['reset_http_request_cache']['submit'] = [
        '#type' => 'submit',
        '#value' => $this->t('Reset HTTP Request Cache'),
        '#description' => $this->t('Note: this will not reset any cached CDN data; see "Advanced Cache" in the "CDN" section.'),
        '#prefix' => '<div>',
        '#suffix' => '</div>',
        '#submit' => [
          [get_class($this), 'submitResetHttpRequestCache'],
        ],
        '#ajax' => [
          'callback' => [get_class($this), 'ajaxResetHttpRequestCache'],
          'wrapper' => 'reset-http-request-cache',
        ],
      ];
    }
  }
}