You are here

public function PageGeneralForm::submitForm in Page Manager 8

Same name and namespace in other branches
  1. 8.4 page_manager_ui/src/Form/PageGeneralForm.php \Drupal\page_manager_ui\Form\PageGeneralForm::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

page_manager_ui/src/Form/PageGeneralForm.php, line 126
Contains \Drupal\page_manager_ui\Form\PageGeneralForm.

Class

PageGeneralForm

Namespace

Drupal\page_manager_ui\Form

Code

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

  /** @var $page \Drupal\page_manager\Entity\Page */
  $page = $cached_values['page'];
  $page
    ->set('description', $form_state
    ->getValue('description'));
  $page
    ->set('path', $form_state
    ->getValue('path'));
  $page
    ->set('use_admin_theme', $form_state
    ->getValue('use_admin_theme'));
  if ($page
    ->isNew()) {
    $page
      ->set('id', $form_state
      ->getValue('id'));
    $page
      ->set('label', $form_state
      ->getValue('label'));
    if (empty($cached_values['variant_plugin_id'])) {
      $variant_plugin_id = $cached_values['variant_plugin_id'] = $form_state
        ->getValue('variant_plugin_id');

      /* @var \Drupal\page_manager\PageVariantInterface $page_variant */
      $page_variant = \Drupal::entityManager()
        ->getStorage('page_variant')
        ->create([
        'variant' => $form_state
          ->getValue('variant_plugin_id'),
        'page' => $page
          ->id(),
        'id' => "{$page->id()}-{$variant_plugin_id}-0",
        'label' => $form['variant_plugin_id']['#options'][$variant_plugin_id],
      ]);
      $page_variant
        ->setPageEntity($page);
      $page
        ->addVariant($page_variant);
      $cached_values['page_variant'] = $page_variant;
    }
    if ($cached_values['variant_plugin_id'] != $form_state
      ->getValue('variant_plugin_id') && !empty($cached_values['page_variant'])) {
      $page_variant = $cached_values['page_variant'];

      /** @var $page_variant \Drupal\page_manager\Entity\PageVariant */
      $page_variant
        ->set('variant', $form_state
        ->getValue('variant_plugin_id'));
      $page_variant
        ->set('variant_settings', []);
      $cached_values['variant_plugin_id'] = $form_state
        ->getValue('variant_plugin_id');
    }
    $cached_values['wizard_options'] = $form_state
      ->getValue('wizard_options');
    $form_state
      ->setTemporaryValue('wizard', $cached_values);
  }
}