public function Settings::submitForm in Courier 2.x
Same name in this branch
- 2.x src/Form/Settings.php \Drupal\courier\Form\Settings::submitForm()
- 2.x courier_system/src/Form/Settings.php \Drupal\courier_system\Form\Settings::submitForm()
Same name and namespace in other branches
- 8 courier_system/src/Form/Settings.php \Drupal\courier_system\Form\Settings::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 ConfigFormBase::submitForm
File
- courier_system/
src/ Form/ Settings.php, line 213
Class
- Settings
- Configure Courier System settings.
Namespace
Drupal\courier_system\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$message = $this
->t('No operations were executed.');
$config = $this
->config('courier_system.settings');
// Template collections keyed by mail ID.
/** @var \Drupal\courier\Entity\GlobalTemplateCollectionInterface[] $global_template_collections */
$global_template_collections = [];
foreach ($this
->getSystemMails() as $module => $mails) {
foreach ($mails as $mail_id => $definition) {
$gtc = GlobalTemplateCollection::load('courier_system.' . $mail_id);
if ($gtc) {
$global_template_collections[$mail_id] = $gtc;
}
}
}
// List of checked mail IDs.
$checkboxes = [];
foreach ($form_state
->getValue([
'list',
'checkboxes',
]) as $id => $checked) {
if ($checked) {
$checkboxes[] = $id;
}
}
$operation = $form_state
->getValue('operation');
$override = $config
->get('override');
foreach ($checkboxes as $mail_id) {
if (isset($global_template_collections[$mail_id])) {
$gtc = $global_template_collections[$mail_id];
$template_collection = $gtc
->getTemplateCollection();
if (in_array($operation, [
'enable',
'disable',
])) {
$enable = $operation == 'enable';
$override[$mail_id] = $enable;
$message = $enable ? $this
->t('Messages enabled.') : $this
->t('Messages disabled.');
}
elseif ($operation == 'delete') {
$message = $this
->t('Messages deleted');
$gtc
->delete();
$template_collection
->delete();
unset($override[$mail_id]);
}
elseif ($operation == 'copy_email') {
$this
->copyCoreToCourierEmail($template_collection, $mail_id);
$template_collection
->save();
$message = $this
->t('Messages copied from Drupal to Courier.');
}
}
}
$config
->set('override', $override)
->save();
$this
->messenger()
->addMessage($message);
}