You are here

public function LayoutChangeSettings::submitForm in Panels 8.3

Same name and namespace in other branches
  1. 8.4 src/Form/LayoutChangeSettings.php \Drupal\panels\Form\LayoutChangeSettings::submitForm()

Form submission handler.

Parameters

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

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

Overrides FormInterface::submitForm

File

src/Form/LayoutChangeSettings.php, line 114

Class

LayoutChangeSettings
Provides a form for configuring a layout's settings.

Namespace

Drupal\panels\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $cached_values = $form_state
    ->getTemporaryValue('wizard');

  /** @var \Drupal\ctools\Wizard\EntityFormWizardInterface $wizard */
  $wizard = $form_state
    ->getFormObject();
  $next_params = $wizard
    ->getNextParameters($cached_values);

  /* @var $plugin \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant */
  $plugin = $cached_values['plugin'];
  $layout_id = !empty($cached_values['layout_change']['new_layout']) ? $cached_values['layout_change']['new_layout'] : $plugin
    ->getConfiguration()['layout'];

  /** @var \Drupal\layout_plugin\Plugin\Layout\LayoutInterface $layout */
  $layout = Layout::layoutPluginManager()
    ->createInstance($layout_id, []);

  // If we're dealing with a form, submit it.
  if ($layout instanceof PluginFormInterface) {
    $sub_form_state = new FormState();
    $plugin_values = $form_state
      ->getValue([
      'layout_settings_wrapper',
      'layout_settings',
    ]);

    // If form values came through the step's submission, handle them.
    if ($plugin_values) {
      $sub_form_state
        ->setValues($plugin_values);
      $layout
        ->submitConfigurationForm($form, $sub_form_state);

      // If this plugin is configurable, get that configuration and set it in
      // cached values.
      if ($layout instanceof ConfigurablePluginInterface) {
        $cached_values = $this
          ->setCachedValues($next_params['step'], $plugin, $layout, $cached_values, $layout
          ->getConfiguration());
      }
    }
    else {
      $cached_values = $this
        ->setCachedValues($next_params['step'], $plugin, $layout, $cached_values, []);
    }
  }
  else {
    $cached_values = $this
      ->setCachedValues($next_params['step'], $plugin, $layout, $cached_values, []);
  }
  $form_state
    ->setTemporaryValue('wizard', $cached_values);
}