1 language.inc language_negotiation_purge()

Removes any unused language negotiation providers from the configuration.

Related topics

File

core/includes/language.inc, line 289
Language Negotiation API.

Code

function language_negotiation_purge() {
  // Ensure that we are getting the defined language negotiation information. An
  // invocation of module_enable() or module_disable() could outdate the cached
  // information.
  backdrop_static_reset('language_negotiation_info');
  backdrop_static_reset('language_types_info');
  backdrop_static_reset('language_types_get_configurable');

  // Do not attempt to read/write to the language settings file if it does not
  // exist, which may happen if this function is called when language.module
  // is not enabled.
  $config = config('language.settings');
  if ($config->isNew()) {
    return;
  }

  $defined_providers = language_negotiation_info();
  $language_types = language_types_info();
  $configured_types = $config->get('language_negotiation');
  foreach ($configured_types as $configured_type => $configured_settings) {
    // Remove the entire language type if it no longer exists.
    if (!isset($language_types[$configured_type])) {
      unset($configured_types[$configured_type]);
    }
    // Remove negotiation providers if they no longer exist.
    $configured_types[$configured_type] = array_values(array_intersect($configured_settings, array_keys($defined_providers)));
  }
  $config->set('language_negotiation', $configured_types);
  $config->save();

  backdrop_static_reset('language_types_info');
  backdrop_static_reset('language_negotiation_info');
}