function yamlform_update_8047 in YAML Form 8
Issue #2793273 by smaz: Send email to form element: Use 'option value' instead of 'option text'.
File
- includes/
yamlform.update.inc, line 949 - YAML Form module update hooks.
Code
function yamlform_update_8047(&$sandbox) {
$ids = [];
// Update 'yamlform.yamlform.*' configuration.
$config_factory = \Drupal::configFactory();
foreach ($config_factory
->listAll('yamlform.yamlform.') as $yamlform_config_name) {
$yamlform_config = $config_factory
->getEditable($yamlform_config_name);
$handlers = $yamlform_config
->get('handlers');
$has_mail_token = FALSE;
foreach ($handlers as $handler_id => $handler) {
if ($handler['id'] != 'email') {
continue;
}
$base = "handlers.{$handler_id}";
$mail_fields = [
'to_mail',
'cc_mail',
'bcc_mail',
'from_mail',
];
foreach ($mail_fields as $mail_field) {
$setting_name = $base . '.settings.' . $mail_field;
$mail = $yamlform_config
->get($setting_name);
if (preg_match('/:value\\]$/', $mail)) {
$mail = preg_replace('/:value\\]$/', ':raw]', $mail);
$yamlform_config
->set($setting_name, $mail);
$has_mail_token = TRUE;
}
}
}
if ($has_mail_token) {
$ids[] = $yamlform_config
->get('id');
$yamlform_config
->save(TRUE);
}
}
if (!empty($ids)) {
$messages[] = t('Updated email handler for forms: @ids', [
'@ids' => implode(', ', array_unique($ids)),
]);
}
return implode("\n", $messages);
}