FlagDisableConfirmForm.php in Flag 8.4
File
src/Form/FlagDisableConfirmForm.php
View source
<?php
namespace Drupal\flag\Form;
use Drupal\flag\FlagInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
class FlagDisableConfirmForm extends ConfirmFormBase {
protected $flag;
public function buildForm(array $form, FormStateInterface $form_state, FlagInterface $flag = NULL) {
$this->flag = $flag;
return parent::buildForm($form, $form_state);
}
public function getFormId() {
return 'flag_disable_confirm_form';
}
public function getQuestion() {
if ($this->flag
->status()) {
return $this
->t('Disable flag @name?', [
'@name' => $this->flag
->label(),
]);
}
return $this
->t('Enable flag @name?', [
'@name' => $this->flag
->label(),
]);
}
public function getCancelUrl() {
return $this->flag
->toUrl('collection');
}
public function getDescription() {
if ($this->flag
->status()) {
return $this
->t('Users will no longer be able to use the flag, but no data will be lost.');
}
return $this
->t('The flag will appear once more on configured nodes.');
}
public function getConfirmText() {
if ($this->flag
->status()) {
return $this
->t('Disable');
}
return $this
->t('Enable');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($this->flag
->status()) {
$this->flag
->disable();
}
else {
$this->flag
->enable();
}
$this->flag
->save();
$form_state
->setRedirect('entity.flag.collection');
}
}