public function Settings::submitCreateMessages in Courier 8
Same name and namespace in other branches
- 2.x courier_system/src/Form/Settings.php \Drupal\courier_system\Form\Settings::submitCreateMessages()
Submit handler for create messages table.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
File
- courier_system/
src/ Form/ Settings.php, line 289
Class
- Settings
- Configure Courier System settings.
Namespace
Drupal\courier_system\FormCode
public function submitCreateMessages(array &$form, FormStateInterface $form_state) {
$config = $this
->config('courier_system.settings');
$override = $config
->get('override');
// Create template collections.
foreach ($form_state
->getValue('table') as $mail_id => $create) {
if ($create) {
$values = [
'id' => 'courier_system.' . $mail_id,
];
$gtc = GlobalTemplateCollection::create($values);
$gtc
->save();
$template_collection = $gtc
->getTemplateCollection();
// Owner.
// @todo set owner when DER can reference configs.
// See issue: https://www.drupal.org/node/2555027
// Context.
// Create global context for accounts if it does not exist.
/** @var \Drupal\courier\CourierContextInterface $courier_context */
if (!($courier_context = CourierContext::load('courier_system_user'))) {
$courier_context = CourierContext::create([
'label' => t('Courier System: Account'),
'id' => 'courier_system_user',
'tokens' => [
'user',
],
]);
$courier_context
->save();
}
$template_collection
->setContext($courier_context);
// Contents.
$this
->copyCoreToCourierEmail($template_collection, $mail_id);
$template_collection
->save();
$override[$mail_id] = TRUE;
}
}
$config
->set('override', $override)
->save();
}