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;
class ContactFormEnableForm extends EntityConfirmFormBase {
public function getQuestion() {
return $this
->t('Are you sure you want to enable the contact form %form?', [
'%form' => $this->entity
->label(),
]);
}
public function getCancelUrl() {
return new Url('entity.contact_form.collection');
}
public function getConfirmText() {
return $this
->t('Enable');
}
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.');
}
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());
}
}