You are here

public function PageVariantAddForm::submitForm in Page Manager 8

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

Class

PageVariantAddForm
Provides a form for adding a variant.

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'];
  $variant_plugin_id = $cached_values['variant_plugin_id'] = $form_state
    ->getValue('variant_plugin_id');

  /** @var $page_variant \Drupal\page_manager\Entity\PageVariant */
  $page_variant = $cached_values['page_variant'];
  $page_variant
    ->setVariantPluginId($variant_plugin_id);
  $page_variant
    ->set('label', $form_state
    ->getValue('label'));
  $page_variant
    ->set('page', $page
    ->id());

  // Loop over variant ids until one is available.
  $variant_id_base = "{$page->id()}-{$variant_plugin_id}";
  $key = 0;
  while ($this
    ->variantExists($page, "{$variant_id_base}-{$key}")) {
    $key++;
  }
  $cached_values['id'] = "{$variant_id_base}-{$key}";
  $page_variant
    ->set('id', $cached_values['id']);
  $cached_values['wizard_options'] = $form_state
    ->getValue('wizard_options');
  $form_state
    ->setTemporaryValue('wizard', $cached_values);
}