public function MessageListForm::submitForm in RNG - Events and Registrations 8
Same name and namespace in other branches
- 8.2 src/Form/MessageListForm.php \Drupal\rng\Form\MessageListForm::submitForm()
- 3.x src/Form/MessageListForm.php \Drupal\rng\Form\MessageListForm::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/ MessageListForm.php, line 168
Class
- MessageListForm
- Creates message list form.
Namespace
Drupal\rng\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$message = NULL;
$operation = $form_state
->getValue([
'operation',
]);
// Checkbox is checked, keyed by rule ID.
$checkbox = $form_state
->getValue([
'list',
'checkboxes',
]);
// A list of checked rules.
$rules = [];
foreach ($this
->getCommunicationRules($form['#rng_event']) as $rule) {
// Checkbox is checked.
if ($checkbox[$rule
->id()]) {
$rules[] = $rule;
}
}
/** @var RuleInterface $rule */
foreach ($rules as $rule) {
if (in_array($operation, [
'enable',
'disable',
])) {
$operation_active = $operation == 'enable';
if ($rule
->isActive() != $operation_active) {
$rule
->setIsActive($operation_active)
->save();
}
$message = $operation == 'enable' ? $this
->t('Messages enabled.') : $this
->t('Messages disabled.');
}
elseif ($operation == 'delete') {
$rule
->delete();
$message = $this
->t('Messages deleted');
}
}
drupal_set_message($message ? $message : $this
->t('No action performed.'));
}