You are here

public function StylesGroupManager::buildStylesFormElements in Bootstrap Styles 1.0.x

Build the layout builder form styles elements.

Parameters

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

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

array $storage: The plugins storage array.

string $filter: The filter config name.

Return value

array The form structure.

File

src/StylesGroup/StylesGroupManager.php, line 155

Class

StylesGroupManager
Provides an StylesGroup plugin manager.

Namespace

Drupal\bootstrap_styles\StylesGroup

Code

public function buildStylesFormElements(array &$form, FormStateInterface $form_state, array $storage, string $filter = NULL) {

  // Restrict styles.
  $allowed_plugins = $this
    ->getAllowedPlugins($filter);
  foreach ($this
    ->getStylesGroups() as $group_key => $style_group) {

    // Check groups restriction.
    if (!empty($allowed_plugins) && !array_key_exists($group_key, $allowed_plugins)) {
      continue;
    }

    // Styles Group.
    if (isset($style_group['styles'])) {
      $group_instance = $this
        ->createInstance($group_key);
      $form[$group_key] = [
        '#type' => 'details',
        '#title' => $group_instance
          ->getTitleWithIcon(),
        '#open' => FALSE,
        '#tree' => TRUE,
      ];
      $form[$group_key] += $group_instance
        ->buildStyleFormElements($form[$group_key], $form_state, $storage);
      foreach ($style_group['styles'] as $style_key => $style) {

        // Check plugins restriction.
        if (!empty($allowed_plugins) && count($allowed_plugins[$group_key]) > 0 && !in_array($style_key, $allowed_plugins[$group_key])) {
          continue;
        }
        $style_instance = $this->styleManager
          ->createInstance($style_key);
        $form[$group_key] += $style_instance
          ->buildStyleFormElements($form[$group_key], $form_state, $storage);
      }
    }
  }
  return $form;
}