1 translation.install translation_update_1001()

Fix Views which still have the Drupal 7 version of the language field and filter. Change from "language" to "langcode".

Related topics

File

core/modules/translation/translation.install, line 39
Install, update and uninstall functions for the Translation module.

Code

function translation_update_1001() {
  $configs = config_get_names_with_prefix('views.view.');

  foreach ($configs as $config_file) {
    $config = config($config_file);
    $displays = $config->get('display');
    foreach ($displays as $display => $display_details) {
      if (isset($display_details['display_options']['filters'])) {
        foreach ($display_details['display_options']['filters'] as $key => $filter) {
          if ($filter['id'] == 'language') {
            $config->set('display.' . $display . '.display_options.filters.' . $key . '.field', 'langcode');
          }
        }
      }
      if (isset($display_details['display_options']['fields'])) {
        foreach ($display_details['display_options']['fields'] as $key => $field) {
          if ($field['id'] == 'language') {
            $config->set('display.' . $display . '.display_options.fields.' . $key . '.field', 'langcode');
          }
        }
      }
    }
    $config->save();
  }
}