You are here

ContactFormEnableForm.php in Contact Storage 8

File

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

namespace Drupal\contact_storage\Form;

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

/**
 * Provides the contact form enable form.
 */
class ContactFormEnableForm extends EntityConfirmFormBase {

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

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

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

  /**
   * {@inheritdoc}
   */
  public function getDescription() {
    return $this
      ->t('Enabling the contact form will make it visible. This action can be undone from the contact forms administration page.');
  }

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

}

Classes

Namesort descending Description
ContactFormEnableForm Provides the contact form enable form.