ConditionDeleteForm.php in Block Visibility Groups 8
File
src/Form/ConditionDeleteForm.php
View source
<?php
namespace Drupal\block_visibility_groups\Form;
use Drupal\block_visibility_groups\ConditionRedirectTrait;
use Drupal\block_visibility_groups\Entity\BlockVisibilityGroup;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
class ConditionDeleteForm extends ConfirmFormBase {
use ConditionRedirectTrait;
protected $block_visibility_group;
protected $condition;
public function getFormId() {
return 'block_visibility_group_manager_condition_delete_form';
}
public function getQuestion() {
return $this
->t('Are you sure you want to delete the condition %name?', [
'%name' => $this->condition
->getPluginDefinition()['label'],
]);
}
public function getCancelUrl() {
return $this->block_visibility_group
->toUrl('edit-form');
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function buildForm(array $form, FormStateInterface $form_state, BlockVisibilityGroup $block_visibility_group = NULL, $condition_id = NULL, $redirect = 'edit') {
$this->block_visibility_group = $block_visibility_group;
$this
->setRedirectValue($form, $redirect);
$this->condition = $block_visibility_group
->getCondition($condition_id);
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->block_visibility_group
->removeCondition($this->condition
->getConfiguration()['uuid']);
$this->block_visibility_group
->save();
$this
->messenger()
->addMessage($this
->t('The condition %name has been removed.', [
'%name' => $this->condition
->getPluginDefinition()['label'],
]));
$this
->setConditionRedirect($form_state);
}
}