You are here

function key_update_8001 in Key 8

Set default value for stripping trailing line breaks.

File

./key.install, line 11
Install, update and uninstall functions for the Key module.

Code

function key_update_8001() {
  $updated = FALSE;
  $config_factory = \Drupal::configFactory();

  // Loop through keys.
  foreach ($config_factory
    ->listAll('key.key.') as $key_config_name) {
    $key = $config_factory
      ->getEditable($key_config_name);

    // If this key uses the File key provider.
    if ($key
      ->get('key_provider') == 'file') {
      $settings = $key
        ->get('key_provider_settings');

      // If the Strip Line Breaks field has not been set.
      if (!isset($settings['strip_line_breaks'])) {

        // Set Strip Line Breaks to FALSE and save the configuration.
        $settings['strip_line_breaks'] = FALSE;
        $key
          ->set('key_provider_settings', $settings);
        $key
          ->save(TRUE);
        $updated = TRUE;
      }
    }
  }
  if ($updated) {
    return t('File key provider settings updated.');
  }
}