ConditionDeleteForm.php in Business Rules 8
File
src/Form/ConditionDeleteForm.php
View source
<?php
namespace Drupal\business_rules\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class ConditionDeleteForm extends EntityConfirmFormBase {
public function getQuestion() {
return $this
->t('Are you sure you want to delete %name? All references to this condition will be removed as well.', [
'%name' => $this->entity
->label(),
]);
}
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$util = \Drupal::service('business_rules.util');
$form['rules_using_this_item'] = $util
->getUsedByBusinessRulesDetailsBox($this->entity);
$form['conditions_using_this_item'] = $util
->getUsedByConditionsDetailsBox($this->entity);
$form['actions_using_this_item'] = $util
->getUsedByActionsDetailsBox($this->entity);
return $form;
}
public function getCancelUrl() {
return new Url('entity.business_rules_condition.collection');
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity
->delete();
drupal_set_message($this
->t('content @type: deleted @label.', [
'@type' => $this->entity
->bundle(),
'@label' => $this->entity
->label(),
]));
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}