public function EventTypeRuleDeleteAll::submitForm in RNG - Events and Registrations 8
Same name and namespace in other branches
- 8.2 src/Form/EventTypeRuleDeleteAll.php \Drupal\rng\Form\EventTypeRuleDeleteAll::submitForm()
- 3.x src/Form/EventTypeRuleDeleteAll.php \Drupal\rng\Form\EventTypeRuleDeleteAll::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- src/
Form/ EventTypeRuleDeleteAll.php, line 111
Class
- EventTypeRuleDeleteAll
- Form controller to delete all custom rules for an event type.
Namespace
Drupal\rng\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\rng\RuleInterface[] $rules */
$rules = $this->ruleStorage
->loadByProperties([
'event__target_type' => $this->eventType
->getEventEntityTypeId(),
]);
// There is no bundle field on rules. Load all rules one-by-one and find
// the bundle for each event.
$count = 0;
foreach ($rules as $rule) {
$event = $rule
->getEvent();
// If event no longer exists then delete the rules while we're here.
if (!$event || $event
->bundle() == $this->eventType
->getEventBundle()) {
$rule
->delete();
$count++;
}
}
drupal_set_message($this
->formatPlural($count, '@count custom access rule deleted.', '@count custom access rules deleted.'));
$this->eventManager
->invalidateEventType($this->eventType);
$form_state
->setRedirectUrl($this
->getCancelUrl());
}