You are here

public function PagererStyleBase::submitConfigurationForm in Pagerer 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/pagerer/PagererStyleBase.php \Drupal\pagerer\Plugin\pagerer\PagererStyleBase::submitConfigurationForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Overrides PluginFormInterface::submitConfigurationForm

File

src/Plugin/pagerer/PagererStyleBase.php, line 350

Class

PagererStyleBase
Base plugin for Pagerer.

Namespace

Drupal\pagerer\Plugin\pagerer

Code

public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  $default_configuration = $this->configFactory
    ->get('pagerer.style.' . $this
    ->getPluginId())
    ->get('default_config');
  $display_mode = $form_state
    ->getValue('display');
  foreach ($default_configuration as $conf_key => $conf_item) {

    // Root level configuration.
    if ($form_state
      ->hasValue($conf_key)) {
      $this->pagererPreset
        ->setPaneData($this->pagererPresetPane, "config.{$conf_key}", $form_state
        ->getValue($conf_key));
    }
    elseif ($conf_key == 'tags') {
      foreach ($conf_item as $tag_key => $tag_value) {

        // Tag options.
        if ($form_state
          ->hasValue($tag_key)) {

          // Display independent.
          $this->pagererPreset
            ->setPaneData($this->pagererPresetPane, "config.tags.{$tag_key}", $form_state
            ->getValue($tag_key));
        }
        elseif (in_array($tag_key, [
          'pages',
          'items',
          'item_ranges',
        ])) {

          // Display dependent block. Saves all the tags for the current
          // display, and only those that changed from default in other
          // displays. This to allow full translation of the current display
          // text elements.
          foreach ($tag_value as $tag_display_key => $tag_display_value) {
            $tag_display_value = $form_state
              ->getValue([
              'tags_container',
              $tag_key,
              $tag_display_key,
            ]);
            if ($tag_key == $display_mode || $tag_display_value != $default_configuration['tags'][$tag_key][$tag_display_key]) {
              $this->pagererPreset
                ->setPaneData($this->pagererPresetPane, "config.tags.{$tag_key}.{$tag_display_key}", $tag_display_value);
            }
            else {
              $this->pagererPreset
                ->unsetPaneData($this->pagererPresetPane, "config.tags.{$tag_key}.{$tag_display_key}");
            }
          }
        }
      }
    }
  }
}