You are here

function _yamlform_update_admin_settings in YAML Form 8

Update admin settings to reflect changes in the default settings.

This function is used to apply new admin settings (in yamlform.settings.yml). If you are moving or updating any admin settings this must be explicitly done via an update hook.

3 calls to _yamlform_update_admin_settings()
drush_yamlform_repair in drush/yamlform.drush.inc
Implements drush_hook_COMMAND().
yamlform_update_8071 in includes/yamlform.update.inc
Issue #2826300: yamlform.settings.yml is out-of-sync and missing default values.
yamlform_update_8074 in includes/yamlform.update.inc
Issue #2833576: Custom confirmation attributes and back link.

File

./yamlform.install, line 105
Install, update and uninstall functions for the YAML Form module.

Code

function _yamlform_update_admin_settings() {
  $admin_config = \Drupal::configFactory()
    ->getEditable('yamlform.settings');
  $current_settings = $admin_config
    ->getRawData();
  $admin_settings = Yaml::decode(file_get_contents(drupal_get_path('module', 'yamlform') . '/config/install/yamlform.settings.yml'));

  // Note, admin settings are always grouped into associative array,
  // except for the langcode.
  foreach ($admin_settings as $group => $settings) {

    // Handle the rare case the we are adding a new group the admin settings.
    if (!isset($current_settings[$group])) {
      continue;
    }

    // Completely copy the format, langcode, and third_party_settings.
    if (in_array($group, [
      'format',
      'langcode',
      'third_party_settings',
    ])) {
      if (isset($current_settings[$group])) {
        $admin_settings[$group] = $current_settings[$group];
      }
    }
    else {

      // Loop through the group's settings and apply all existing settings to
      // the default admin settings.
      foreach ($settings as $name => $value) {
        if (isset($current_settings[$group][$name])) {
          $admin_settings[$group][$name] = $current_settings[$group][$name];
        }
      }
    }
  }
  $admin_config
    ->setData($admin_settings)
    ->save();
}