diff --git a/core/modules/system/tests/fixtures/update/drupal-8.views-taxonomy-parent-2543726.yml b/core/modules/system/tests/fixtures/update/drupal-8.views-taxonomy-parent-2543726.yml index 65df6a80e8..de8f63d7c4 100644 --- a/core/modules/system/tests/fixtures/update/drupal-8.views-taxonomy-parent-2543726.yml +++ b/core/modules/system/tests/fixtures/update/drupal-8.views-taxonomy-parent-2543726.yml @@ -116,7 +116,95 @@ display: link_to_entity: true entity_type: taxonomy_term entity_field: name - filters: { } + filters: + parent: + id: parent + table: taxonomy_term_hierarchy + field: parent + relationship: field_tags + group_type: group + admin_label: '' + operator: '=' + value: + min: '' + max: '' + value: '' + group: 1 + exposed: true + expose: + operator_id: parent_op + label: 'Parent term' + description: '' + use_operator: false + operator: parent_op + identifier: parent + required: false + remember: false + multiple: false + remember_roles: + authenticated: authenticated + anonymous: '0' + administrator: '0' + placeholder: '' + min_placeholder: '' + max_placeholder: '' + is_grouped: false + group_info: + label: '' + description: '' + identifier: '' + optional: true + widget: select + multiple: false + remember: false + default_group: All + default_group_multiple: { } + group_items: { } + plugin_id: numeric + parent_1: + id: parent_1 + table: taxonomy_term_hierarchy + field: parent + relationship: field_tags + group_type: group + admin_label: '' + operator: '=' + value: + min: '' + max: '' + value: '' + group: 1 + exposed: true + expose: + operator_id: parent_1_op + label: 'Parent term' + description: '' + use_operator: false + operator: parent_1_op + identifier: parent_1 + required: false + remember: false + multiple: false + remember_roles: + authenticated: authenticated + anonymous: '0' + administrator: '0' + placeholder: '' + min_placeholder: '' + max_placeholder: '' + is_grouped: false + group_info: + label: '' + description: '' + identifier: '' + optional: true + widget: select + multiple: false + remember: false + default_group: All + default_group_multiple: { } + group_items: { } + plugin_id: numeric sorts: { } header: { } footer: { } diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index e5f4fe3a9f..c1a18bcb2c 100644 --- a/core/modules/taxonomy/taxonomy.install +++ b/core/modules/taxonomy/taxonomy.install @@ -90,43 +90,39 @@ function taxonomy_update_8502(&$sandbox) { */ function taxonomy_update_8503() { $config_factory = \Drupal::configFactory(); + foreach ($config_factory->listAll('views.view.') as $id) { $view = $config_factory->getEditable($id); - $changed = FALSE; foreach (array_keys($view->get('display')) as $display_id) { - $base_path = "display.$display_id.display_options.relationships.parent"; - $table_path = $base_path . '.table'; - $field_path = $base_path . '.field'; - - if (!empty($table = $view->get($table_path)) && $table == 'taxonomy_term_hierarchy') { - $view->set($table_path, 'taxonomy_term__parent'); - $view->set($field_path, 'parent_target_id'); + $changed = FALSE; - $base_path = "display.{$display_id}.display_options.filters.parent"; - $table_path = $base_path . '.table'; - $field_path = $base_path . '.field'; + foreach (['relationships', 'filters', 'arguments'] as $handler_type) { + $base_path = "display.$display_id.display_options.$handler_type"; + $handlers = $view->get($base_path); - if (!empty($table = $view->get($table_path)) && $table == 'taxonomy_term_hierarchy') { - $view->set($table_path, 'taxonomy_term__parent'); - $view->set($field_path, 'parent_target_id'); + if (!$handlers) { + continue; } - $base_path = "display.{$display_id}.display_options.arguments.parent.table"; - $table_path = $base_path . '.table'; - $field_path = $base_path . '.field'; + foreach ($handlers as $handler_key => $handler_config) { + $table_path = "$base_path.$handler_key.table"; + $field_path = "$base_path.$handler_key.field"; + $table = $view->get($table_path); + $field = $view->get($field_path); - if (!empty($table = $view->get($table_path)) && $table == 'taxonomy_term_hierarchy') { - $view->set($table_path, 'taxonomy_term__parent'); - $view->set($field_path, 'parent_target_id'); - } + if (($table && ($table === 'taxonomy_term_hierarchy')) && ($field && ($field === 'parent'))) { + $view->set($table_path, 'taxonomy_term__parent'); + $view->set($field_path, 'parent_target_id'); - $changed = TRUE; + $changed = TRUE; + } + } } - } - if ($changed) { - $view->save(TRUE); + if ($changed) { + $view->save(TRUE); + } } } } diff --git a/core/modules/taxonomy/tests/src/Functional/Update/TaxonomyParentUpdateTest.php b/core/modules/taxonomy/tests/src/Functional/Update/TaxonomyParentUpdateTest.php index 68e84e031c..1cbe8b49ac 100644 --- a/core/modules/taxonomy/tests/src/Functional/Update/TaxonomyParentUpdateTest.php +++ b/core/modules/taxonomy/tests/src/Functional/Update/TaxonomyParentUpdateTest.php @@ -70,8 +70,18 @@ public function testTaxonomyUpdateParents() { // Test if the view has been converted to use the {taxonomy_term__parent} // table instead of the {taxonomy_term_hierarchy} table. $view = $this->config("views.view.test_taxonomy_parent"); - $path = 'display.default.display_options.relationships.parent.table'; - $this->assertSame($view->get($path), 'taxonomy_term__parent'); + + $relationship_base_path = 'display.default.display_options.relationships.parent'; + $this->assertSame($view->get("$relationship_base_path.table"), 'taxonomy_term__parent'); + $this->assertSame($view->get("$relationship_base_path.field"), 'parent_target_id'); + + $filters_base_path_1 = 'display.default.display_options.filters.parent'; + $this->assertSame($view->get("$filters_base_path_1.table"), 'taxonomy_term__parent'); + $this->assertSame($view->get("$filters_base_path_1.field"), 'parent_target_id'); + + $filters_base_path_2 = 'display.default.display_options.filters.parent'; + $this->assertSame($view->get("$filters_base_path_2.table"), 'taxonomy_term__parent'); + $this->assertSame($view->get("$filters_base_path_2.field"), 'parent_target_id'); // The {taxonomy_term_hierarchy} table has been removed. $this->assertFalse($this->db->schema()->tableExists('taxonomy_term_hierarchy'));