You are here

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

Save styles.

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 $tree: An array of parents.

array $storage: The plugins storage array.

string $filter: The filter config name.

Return value

array An array of plugins with its storage values.

File

src/StylesGroup/StylesGroupManager.php, line 208

Class

StylesGroupManager
Provides an StylesGroup plugin manager.

Namespace

Drupal\bootstrap_styles\StylesGroup

Code

public function submitStylesFormElements(array &$form, FormStateInterface $form_state, array $tree = [], array $storage = [], $filter = NULL) {
  $options = [];

  // 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 ($form_state
      ->getValue(array_merge($tree, [
      $group_key,
    ]))) {
      $group_elements = $form_state
        ->getValue(array_merge($tree, [
        $group_key,
      ]));

      // Submit group form.
      $group_instance = $this
        ->createInstance($group_key);
      $options += $group_instance
        ->submitStyleFormElements($group_elements);

      // Styles Group.
      if (isset($style_group['styles'])) {
        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;
          }

          // Submit style form.
          $style_instance = $this->styleManager
            ->createInstance($style_key);
          $options += $style_instance
            ->submitStyleFormElements($group_elements);
        }
      }
    }
  }
  return array_merge($storage, $options);
}