You are here

public function PageVariantDeleteForm::submitForm in Page Manager 8

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

Class

PageVariantDeleteForm
Builds the form to delete a PageVariant.

Namespace

Drupal\page_manager_ui\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $machine_name = $this
    ->getRouteMatch()
    ->getParameter('machine_name');
  $variant_machine_name = $this
    ->getRouteMatch()
    ->getParameter('variant_machine_name');
  $cached_values = $this->tempstore
    ->get($this
    ->getTempstoreId())
    ->get($machine_name);

  /** @var \Drupal\page_manager\PageInterface $page */
  $page = $cached_values['page'];
  $page_variant = $page
    ->getVariant($variant_machine_name);

  // Add to a list to remove for real later.
  $cached_values['deleted_variants'][$variant_machine_name] = $page_variant;
  drupal_set_message($this
    ->t('The variant %label has been removed.', [
    '%label' => $page_variant
      ->label(),
  ]));
  $form_state
    ->setRedirectUrl($this
    ->getCancelUrl());
  $this->tempstore
    ->get($this
    ->getTempstoreId())
    ->set($page
    ->id(), $cached_values);
}