You are here

PatternDisableForm.php in Pathauto 8

File

src/Form/PatternDisableForm.php
View source
<?php

namespace Drupal\pathauto\Form;

use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;

/**
 * Provides the pathauto pattern disable disable form.
 */
class PatternDisableForm extends EntityConfirmFormBase {

  /**
   * {@inheritdoc}
   */
  public function getQuestion() {
    return $this
      ->t('Are you sure you want to disable the pattern %label?', [
      '%label' => $this->entity
        ->label(),
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getCancelUrl() {
    return new Url('entity.pathauto_pattern.collection');
  }

  /**
   * {@inheritdoc}
   */
  public function getConfirmText() {
    return $this
      ->t('Disable');
  }

  /**
   * {@inheritdoc}
   */
  public function getDescription() {
    return $this
      ->t('Disabled patterns are ignored when generating aliases.');
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->entity
      ->disable()
      ->save();
    $this
      ->messenger()
      ->addMessage($this
      ->t('Disabled pattern %label.', [
      '%label' => $this->entity
        ->label(),
    ]));
    $form_state
      ->setRedirectUrl($this
      ->getCancelUrl());
  }

}

Classes

Namesort descending Description
PatternDisableForm Provides the pathauto pattern disable disable form.