CheckEnableForm.php in Production check & Production monitor 8
File
src/Form/CheckEnableForm.php
View source
<?php
namespace Drupal\prod_check\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class CheckEnableForm extends EntityConfirmFormBase {
public function getQuestion() {
return $this
->t('Are you sure you want to enable the production check %check?', [
'%check' => $this->entity
->label(),
]);
}
public function getCancelUrl() {
return new Url('entity.prod_check.collection');
}
public function getConfirmText() {
return $this
->t('Enable');
}
public function getDescription() {
return $this
->t('Enabled this production check.');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity
->enable()
->save();
$this
->messenger()
->addMessage($this
->t('Disabled production check %check.', [
'%check' => $this->entity
->label(),
]));
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}