Skip to content

Commit

Permalink
Issue backdrop#4698: Update Drupal 7 language fields and filters in V…
Browse files Browse the repository at this point in the history
  • Loading branch information
herbdool committed Nov 6, 2020
1 parent 042872e commit 36a4266
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions core/modules/translation/translation.install
Expand Up @@ -4,6 +4,17 @@
* Install, update and uninstall functions for the Translation module.
*/

/**
* Implements hook_update_dependencies().
*/
function translation_update_dependencies() {
// Do not fix language fields until after Views are converted to config.
$dependencies['translation'][1001] = array(
'views' => 1001,
);
return $dependencies;
}

/**
* @addtogroup updates-7.x-to-1.x
* @{
Expand All @@ -21,6 +32,36 @@ function translation_update_1000() {
update_variable_del('translation_language_type');
}

/**
* Fix Views which still have the Drupal 7 version of the language field and
* filter. Change from "language" to "langcode".
*/
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();
}
}

/**
* @} End of "addtogroup updates-7.x-to-1.x"
* The next series of updates should start at 2000.
Expand Down

0 comments on commit 36a4266

Please sign in to comment.