You are here

function webform_update_8042 in Webform 6.x

Same name and namespace in other branches
  1. 8.5 includes/webform.install.update.inc \webform_update_8042()

Issue #2875371: Can't Add Email Handler w/Select "Send To".

File

includes/webform.install.update.inc, line 877
Archived Webform update hooks.

Code

function webform_update_8042() {
  $settings = [
    'to_options',
    'cc_options',
    'bcc_options',
    'from_options',
  ];
  $config_factory = \Drupal::configFactory();
  foreach ($config_factory
    ->listAll('webform.webform.') as $webform_config_name) {
    $webform_config = $config_factory
      ->getEditable($webform_config_name);
    $data = $webform_config
      ->getRawData();
    $has_email_handler = FALSE;
    foreach ($data['handlers'] as &$handler) {
      if (in_array($handler['id'], [
        'email',
        'scheduled_email',
      ])) {
        foreach ($settings as $setting_name) {
          if (!empty($handler['settings'][$setting_name])) {
            $has_email_handler = TRUE;
            $handler['settings'][$setting_name] = WebformOptionsHelper::encodeConfig($handler['settings'][$setting_name]);
          }
        }
      }
    }
    if ($has_email_handler) {
      $webform_config
        ->setData($data);
      $webform_config
        ->save();
    }
  }
}