You are here

function _webform_update_string_replace in Webform 6.x

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

Replace string in webform.settings.yml and webform.webform.*.yml.

Parameters

string $search: String to be search for.

string $replace: String to be replace with.

3 calls to _webform_update_string_replace()
webform_update_8002 in includes/webform.install.update.inc
Issue #2834572: Refactor and improve token management.
webform_update_8118 in includes/webform.install.update.inc
Issue #2957074: Invalid Tokens in Email Handler.
webform_update_8123 in includes/webform.install.update.inc
Issue #2962442: Remove [webform-authenticated-user] token and use [current-user] token with clear value option.

File

includes/webform.install.inc, line 367
Webform install helper functions.

Code

function _webform_update_string_replace($search, $replace) {
  $config_factory = \Drupal::configFactory();

  // Update 'webform.settings' configuration.
  $settings_config = \Drupal::configFactory()
    ->getEditable('webform.settings');
  $yaml = Yaml::encode($settings_config
    ->getRawData());
  if (strpos($yaml, $search) !== FALSE) {
    $yaml = str_replace($search, $replace, $yaml);
    $settings_config
      ->setData(Yaml::decode($yaml));
    $settings_config
      ->save();
  }

  // Update 'webform.webform.*' configuration.
  foreach ($config_factory
    ->listAll('webform.webform.') as $webform_config_name) {
    $webform_config = $config_factory
      ->getEditable($webform_config_name);
    $yaml = Yaml::encode($webform_config
      ->getRawData());
    if (strpos($yaml, $search) !== FALSE) {
      $yaml = str_replace($search, $replace, $yaml);
      $webform_config
        ->setData(Yaml::decode($yaml));
      $webform_config
        ->save();
    }
  }
}