DisableForm.php in Content Moderation Notifications 8.3
File
src/Form/DisableForm.php
View source
<?php
namespace Drupal\content_moderation_notifications\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
class DisableForm extends EntityConfirmFormBase {
protected $notification;
public function buildForm(array $form, FormStateInterface $form_state) {
$this->notification = $this->entity;
return parent::buildForm($form, $form_state);
}
public function getQuestion() {
if ($this->notification
->status()) {
return $this
->t('Disable notification %label?', [
'%label' => $this->notification
->label(),
]);
}
return $this
->t('Enable notification %label?', [
'%label' => $this->notification
->label(),
]);
}
public function getDescription() {
if ($this->notification
->status()) {
return $this
->t('Emails will not be sent for this notification when it is disabled.');
}
return $this
->t('Emails will be sent for this notification when it is enabled.');
}
public function getCancelUrl() {
return $this->notification
->toUrl('collection');
}
public function getFormId() {
return 'content_moderation_notification_disable_confirm_form';
}
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($this->notification
->status()) {
$this->notification
->disable();
}
else {
$this->notification
->enable();
}
$this->notification
->save();
$form_state
->setRedirect('entity.content_moderation_notification.collection');
}
}
Classes
Name |
Description |
DisableForm |
The enable/disable form for content moderation notification entities. |