From 678efa0b79d8a32bd3554cae21e3b96005db2295 Mon Sep 17 00:00:00 2001 From: David Cameron <david@cadeyrn.us> Date: Fri, 21 Mar 2025 23:03:54 -0500 Subject: [PATCH 01/15] Views text area format dependency --- .../views/src/Plugin/views/area/Text.php | 43 ++++++++++++++++- .../tests/src/Unit/Plugin/area/TextTest.php | 48 +++++++++++++++++++ 2 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 core/modules/views/tests/src/Unit/Plugin/area/TextTest.php diff --git a/core/modules/views/src/Plugin/views/area/Text.php b/core/modules/views/src/Plugin/views/area/Text.php index f37c7eb8b3aa..dc133e7edfbc 100644 --- a/core/modules/views/src/Plugin/views/area/Text.php +++ b/core/modules/views/src/Plugin/views/area/Text.php @@ -2,8 +2,10 @@ namespace Drupal\views\Plugin\views\area; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\views\Attribute\ViewsArea; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Views area text handler. @@ -13,6 +15,22 @@ #[ViewsArea("text")] class Text extends TokenizeAreaPluginBase { + public function __construct(array $configuration, $plugin_id, $plugin_definition, protected EntityTypeManagerInterface $entityTypeManager) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('entity_type.manager') + ); + } + /** * {@inheritdoc} */ @@ -38,7 +56,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { '#type' => 'text_format', '#default_value' => $this->options['content']['value'], '#rows' => 6, - '#format' => $this->options['content']['format'] ?? filter_default_format(), + '#format' => $this->getFormatId(), '#editor' => FALSE, ]; } @@ -58,7 +76,7 @@ public function preQuery() { * {@inheritdoc} */ public function render($empty = FALSE) { - $format = $this->options['content']['format'] ?? filter_default_format(); + $format = $this->getFormatId(); if (!$empty || !empty($this->options['empty'])) { return [ '#type' => 'processed_text', @@ -70,4 +88,25 @@ public function render($empty = FALSE) { return []; } + /** + * {@inheritdoc} + */ + public function calculateDependencies() { + $format = $this->entityTypeManager->getStorage('text_format') + ->load($this->getFormatId()); + return [ + $format->getConfigDependencyKey() => $format->getConfigDependencyName(), + ]; + } + + /** + * Returns the ID of the text format used for this area. + * + * @return string + * The text format ID. + */ + protected function getFormatId() { + return $this->options['content']['format'] ?? filter_default_format(); + } + } diff --git a/core/modules/views/tests/src/Unit/Plugin/area/TextTest.php b/core/modules/views/tests/src/Unit/Plugin/area/TextTest.php new file mode 100644 index 000000000000..0aadff819d55 --- /dev/null +++ b/core/modules/views/tests/src/Unit/Plugin/area/TextTest.php @@ -0,0 +1,48 @@ +<?php + +namespace Drupal\Tests\views\Unit\Plugin\area; + +use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\filter\FilterFormatInterface; +use Drupal\Tests\UnitTestCase; +use Drupal\views\Plugin\views\area\Text; + +/** + * @coversDefaultClass \Drupal\views\Plugin\views\area\Text + * @group views + */ +class TextTest extends UnitTestCase { + + /** + * @covers ::calculateDependencies + */ + public function testCalculateDependencies(): void { + $dependency_key = 'test_key'; + $format_id = 'test_format'; + + $format = $this->createMock(FilterFormatInterface::class); + $format->expects($this->once()) + ->method('getConfigDependencyKey') + ->willReturn($dependency_key); + $format->expects($this->once()) + ->method('getConfigDependencyName') + ->willReturn('filter.' . $format_id); + $format_storage = $this->createMock(EntityStorageInterface::class); + $format_storage->expects($this->once()) + ->method('load') + ->with($format_id) + ->willReturn($format); + $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class); + $entity_type_manager->expects($this->once()) + ->method('getStorage') + ->with('text_format') + ->willReturn($format_storage); + + $plugin = new Text([], 'text', [], $entity_type_manager); + $plugin->options['content']['format'] = $format_id; + $expected = [$dependency_key => 'filter.' . $format_id]; + $this->assertEquals($expected, $plugin->calculateDependencies()); + } + +} -- GitLab From 5412697ad2129d8c972ad0f5a47af62369275efd Mon Sep 17 00:00:00 2001 From: David Cameron <david@cadeyrn.us> Date: Fri, 21 Mar 2025 23:07:59 -0500 Subject: [PATCH 02/15] phpcs --- core/modules/views/tests/src/Unit/Plugin/area/TextTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/modules/views/tests/src/Unit/Plugin/area/TextTest.php b/core/modules/views/tests/src/Unit/Plugin/area/TextTest.php index 0aadff819d55..e1b768fdd154 100644 --- a/core/modules/views/tests/src/Unit/Plugin/area/TextTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/area/TextTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\views\Unit\Plugin\area; use Drupal\Core\Entity\EntityStorageInterface; -- GitLab From 6f7b61933ad6280a8fc88957d7abd41f067ffefc Mon Sep 17 00:00:00 2001 From: David Cameron <david@cadeyrn.us> Date: Fri, 21 Mar 2025 23:29:24 -0500 Subject: [PATCH 03/15] Corrected the entity type name --- core/modules/views/src/Plugin/views/area/Text.php | 2 +- core/modules/views/tests/src/Unit/Plugin/area/TextTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/modules/views/src/Plugin/views/area/Text.php b/core/modules/views/src/Plugin/views/area/Text.php index dc133e7edfbc..7c935b19626a 100644 --- a/core/modules/views/src/Plugin/views/area/Text.php +++ b/core/modules/views/src/Plugin/views/area/Text.php @@ -92,7 +92,7 @@ public function render($empty = FALSE) { * {@inheritdoc} */ public function calculateDependencies() { - $format = $this->entityTypeManager->getStorage('text_format') + $format = $this->entityTypeManager->getStorage('filter_format') ->load($this->getFormatId()); return [ $format->getConfigDependencyKey() => $format->getConfigDependencyName(), diff --git a/core/modules/views/tests/src/Unit/Plugin/area/TextTest.php b/core/modules/views/tests/src/Unit/Plugin/area/TextTest.php index e1b768fdd154..e655dd604530 100644 --- a/core/modules/views/tests/src/Unit/Plugin/area/TextTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/area/TextTest.php @@ -38,7 +38,7 @@ public function testCalculateDependencies(): void { $entity_type_manager = $this->createMock(EntityTypeManagerInterface::class); $entity_type_manager->expects($this->once()) ->method('getStorage') - ->with('text_format') + ->with('filter_format') ->willReturn($format_storage); $plugin = new Text([], 'text', [], $entity_type_manager); -- GitLab From 02ba0f70b2cfb75c38b92f4d9e416a8470533657 Mon Sep 17 00:00:00 2001 From: David Cameron <david@cadeyrn.us> Date: Sat, 22 Mar 2025 17:37:25 -0500 Subject: [PATCH 04/15] Formatted the return value of calculateDependencies() correctly --- core/modules/views/src/Plugin/views/area/Text.php | 2 +- core/modules/views/tests/src/Unit/Plugin/area/TextTest.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/modules/views/src/Plugin/views/area/Text.php b/core/modules/views/src/Plugin/views/area/Text.php index 7c935b19626a..9d1a354c5f15 100644 --- a/core/modules/views/src/Plugin/views/area/Text.php +++ b/core/modules/views/src/Plugin/views/area/Text.php @@ -95,7 +95,7 @@ public function calculateDependencies() { $format = $this->entityTypeManager->getStorage('filter_format') ->load($this->getFormatId()); return [ - $format->getConfigDependencyKey() => $format->getConfigDependencyName(), + $format->getConfigDependencyKey() => [$format->getConfigDependencyName()], ]; } diff --git a/core/modules/views/tests/src/Unit/Plugin/area/TextTest.php b/core/modules/views/tests/src/Unit/Plugin/area/TextTest.php index e655dd604530..3d5f3dd485df 100644 --- a/core/modules/views/tests/src/Unit/Plugin/area/TextTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/area/TextTest.php @@ -20,7 +20,7 @@ class TextTest extends UnitTestCase { * @covers ::calculateDependencies */ public function testCalculateDependencies(): void { - $dependency_key = 'test_key'; + $dependency_key = 'config'; $format_id = 'test_format'; $format = $this->createMock(FilterFormatInterface::class); @@ -29,7 +29,7 @@ public function testCalculateDependencies(): void { ->willReturn($dependency_key); $format->expects($this->once()) ->method('getConfigDependencyName') - ->willReturn('filter.' . $format_id); + ->willReturn('filter.format.' . $format_id); $format_storage = $this->createMock(EntityStorageInterface::class); $format_storage->expects($this->once()) ->method('load') @@ -43,7 +43,7 @@ public function testCalculateDependencies(): void { $plugin = new Text([], 'text', [], $entity_type_manager); $plugin->options['content']['format'] = $format_id; - $expected = [$dependency_key => 'filter.' . $format_id]; + $expected = [$dependency_key => ['filter.format.' . $format_id]]; $this->assertEquals($expected, $plugin->calculateDependencies()); } -- GitLab From 8aa8d88992774eeb0d4aebdb0937ee17ec4ac631 Mon Sep 17 00:00:00 2001 From: David Cameron <david@cadeyrn.us> Date: Sat, 22 Mar 2025 18:31:55 -0500 Subject: [PATCH 05/15] Fixed TokenReplaceTest --- .../test_views/views.view.test_tokens.yml | 4 ++-- .../views/tests/src/Kernel/TokenReplaceTest.php | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_tokens.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_tokens.yml index 7dc33c342b0f..0d01f95e215f 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_tokens.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_tokens.yml @@ -105,7 +105,7 @@ display: tokenize: false content: value: "Total rows: [view:total-rows] - Page count: [view:page-count]" - format: basic_html + format: plain_text plugin_id: text page_4: display_plugin: page @@ -137,5 +137,5 @@ display: tokenize: false content: value: "Total rows: [view:total-rows]" - format: basic_html + format: plain_text plugin_id: text diff --git a/core/modules/views/tests/src/Kernel/TokenReplaceTest.php b/core/modules/views/tests/src/Kernel/TokenReplaceTest.php index b90e98f3ad89..7ba54581ac9d 100644 --- a/core/modules/views/tests/src/Kernel/TokenReplaceTest.php +++ b/core/modules/views/tests/src/Kernel/TokenReplaceTest.php @@ -18,7 +18,7 @@ class TokenReplaceTest extends ViewsKernelTestBase { /** * {@inheritdoc} */ - protected static $modules = ['system']; + protected static $modules = ['filter', 'system']; /** * Views used by this test. @@ -27,6 +27,14 @@ class TokenReplaceTest extends ViewsKernelTestBase { */ public static $testViews = ['test_tokens', 'test_invalid_tokens']; + /** + * {@inheritdoc} + */ + protected function setUpFixtures() { + $this->installConfig('filter'); + parent::setUpFixtures(); + } + /** * Tests core token replacements generated from a view. */ -- GitLab From d8ecf5ebaab1aa2773025e81c18840850bfb871f Mon Sep 17 00:00:00 2001 From: David Cameron <david@cadeyrn.us> Date: Sat, 22 Mar 2025 18:53:45 -0500 Subject: [PATCH 06/15] Added a format dependency to views.view.frontpage --- core/profiles/demo_umami/config/install/views.view.frontpage.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/core/profiles/demo_umami/config/install/views.view.frontpage.yml b/core/profiles/demo_umami/config/install/views.view.frontpage.yml index b8dc220f4c8f..6eef474c9df9 100644 --- a/core/profiles/demo_umami/config/install/views.view.frontpage.yml +++ b/core/profiles/demo_umami/config/install/views.view.frontpage.yml @@ -4,6 +4,7 @@ dependencies: config: - core.entity_view_mode.node.card_common - core.entity_view_mode.node.rss + - filter.format.full_html - node.type.recipe module: - node -- GitLab From 60cf6ac3226e68c22629094bdc657217c47b6998 Mon Sep 17 00:00:00 2001 From: David Cameron <david@cadeyrn.us> Date: Sat, 22 Mar 2025 19:05:12 -0500 Subject: [PATCH 07/15] Fixed EntityArgumentTest --- .../test_views/views.view.test_entity_id_argument.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_id_argument.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_id_argument.yml index c74d28db5ba6..adbe58e19404 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_id_argument.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_id_argument.yml @@ -156,7 +156,7 @@ display: tokenize: true content: value: 'title {{ arguments.field_views_testing_tags_target_id }}, input {{ raw_arguments.field_views_testing_tags_target_id }}' - format: basic_html + format: plain_text plugin_id: text footer: { } empty: { } -- GitLab From 6fb153db3b82c243ba66cf91c9e057dc9b573221 Mon Sep 17 00:00:00 2001 From: David Cameron <david@cadeyrn.us> Date: Sat, 22 Mar 2025 19:11:08 -0500 Subject: [PATCH 08/15] Updated AssetAggregationAcrossPagesTest --- .../FunctionalJavascript/AssetAggregationAcrossPagesTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/profiles/demo_umami/tests/src/FunctionalJavascript/AssetAggregationAcrossPagesTest.php b/core/profiles/demo_umami/tests/src/FunctionalJavascript/AssetAggregationAcrossPagesTest.php index 270848ef1500..d651f2722f7c 100644 --- a/core/profiles/demo_umami/tests/src/FunctionalJavascript/AssetAggregationAcrossPagesTest.php +++ b/core/profiles/demo_umami/tests/src/FunctionalJavascript/AssetAggregationAcrossPagesTest.php @@ -50,7 +50,7 @@ public function testFrontAndRecipesPagesAuthenticated(): void { 'ScriptCount' => 3, 'ScriptBytes' => 170500, 'StylesheetCount' => 5, - 'StylesheetBytes' => 86650, + 'StylesheetBytes' => 86100, ]; $this->assertMetrics($expected, $performance_data); } @@ -71,7 +71,7 @@ public function testFrontAndRecipesPagesEditor(): void { 'ScriptCount' => 5, 'ScriptBytes' => 338200, 'StylesheetCount' => 5, - 'StylesheetBytes' => 206750, + 'StylesheetBytes' => 206200, ]; $this->assertMetrics($expected, $performance_data); } -- GitLab From 7353ae18d71fea46bfc94b40dae9b3a528a7883d Mon Sep 17 00:00:00 2001 From: David Cameron <david@cadeyrn.us> Date: Sat, 22 Mar 2025 19:17:11 -0500 Subject: [PATCH 09/15] Fixed TokenReplaceTest --- core/modules/views/tests/src/Kernel/TokenReplaceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/views/tests/src/Kernel/TokenReplaceTest.php b/core/modules/views/tests/src/Kernel/TokenReplaceTest.php index 7ba54581ac9d..e55ca736bb32 100644 --- a/core/modules/views/tests/src/Kernel/TokenReplaceTest.php +++ b/core/modules/views/tests/src/Kernel/TokenReplaceTest.php @@ -30,7 +30,7 @@ class TokenReplaceTest extends ViewsKernelTestBase { /** * {@inheritdoc} */ - protected function setUpFixtures() { + protected function setUpFixtures(): void { $this->installConfig('filter'); parent::setUpFixtures(); } -- GitLab From 6e652d94bed2f3255cd7fa1cba2aa82794639060 Mon Sep 17 00:00:00 2001 From: David Cameron <david@cadeyrn.us> Date: Sat, 22 Mar 2025 22:31:53 -0500 Subject: [PATCH 10/15] Added an update function --- core/modules/views/views.post_update.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/modules/views/views.post_update.php b/core/modules/views/views.post_update.php index c3f352e99a42..66acd0cdb80e 100644 --- a/core/modules/views/views.post_update.php +++ b/core/modules/views/views.post_update.php @@ -6,6 +6,7 @@ */ use Drupal\Core\Config\Entity\ConfigEntityUpdater; +use Drupal\views\Entity\View; use Drupal\views\ViewEntityInterface; use Drupal\views\ViewsConfigUpdater; @@ -87,3 +88,17 @@ function views_post_update_table_css_class(?array &$sandbox = NULL): void { return $view_config_updater->needsTableCssClassUpdate($view); }); } + +/** + * Fix views with filter_format dependencies. + */ +function views_post_update_filter_format_dependencies() { + $views = View::loadMultiple(); + array_walk($views, function (View $view) { + $old_dependencies = $view->getDependencies(); + $new_dependencies = $view->calculateDependencies()->getDependencies(); + if ($old_dependencies !== $new_dependencies) { + $view->save(); + } + }); +} -- GitLab From 57567549740bc9422366ef1b1f961153651eed23 Mon Sep 17 00:00:00 2001 From: David Cameron <david@cadeyrn.us> Date: Sat, 22 Mar 2025 23:09:08 -0500 Subject: [PATCH 11/15] Added the update path test --- .../test_filter_format_dependencies.php | 19 ++ ...s.view.test_filter_format_dependencies.yml | 197 ++++++++++++++++++ .../FilterFormatDependencyUpdateTest.php | 42 ++++ 3 files changed, 258 insertions(+) create mode 100644 core/modules/views/tests/fixtures/update/test_filter_format_dependencies.php create mode 100644 core/modules/views/tests/fixtures/update/views.view.test_filter_format_dependencies.yml create mode 100644 core/modules/views/tests/src/Functional/Update/FilterFormatDependencyUpdateTest.php diff --git a/core/modules/views/tests/fixtures/update/test_filter_format_dependencies.php b/core/modules/views/tests/fixtures/update/test_filter_format_dependencies.php new file mode 100644 index 000000000000..15db7f011a2a --- /dev/null +++ b/core/modules/views/tests/fixtures/update/test_filter_format_dependencies.php @@ -0,0 +1,19 @@ +<?php + +/** + * @file + * Test fixture. + */ + +use Drupal\Core\Database\Database; +use Drupal\Core\Serialization\Yaml; + +$connection = Database::getConnection(); + +$connection->insert('config') + ->fields([ + 'collection' => '', + 'name' => 'views.view.test_filter_format_dependencies', + 'data' => serialize(Yaml::decode(file_get_contents('core/modules/views/tests/fixtures/update/views.view.test_filter_format_dependencies.yml'))), + ]) + ->execute(); diff --git a/core/modules/views/tests/fixtures/update/views.view.test_filter_format_dependencies.yml b/core/modules/views/tests/fixtures/update/views.view.test_filter_format_dependencies.yml new file mode 100644 index 000000000000..ff5d011800ab --- /dev/null +++ b/core/modules/views/tests/fixtures/update/views.view.test_filter_format_dependencies.yml @@ -0,0 +1,197 @@ +uuid: d5e0758d-7f56-4a6a-ab24-86b7d73d5801 +langcode: en +status: true +dependencies: + module: + - node + - user +id: test_filter_format_dependencies +label: test_filter_format_dependencies +module: views +description: '' +tag: '' +base_table: node_field_data +base_field: nid +display: + default: + id: default + display_title: Default + display_plugin: default + position: 0 + display_options: + title: test_filter_format_dependencies + fields: + title: + id: title + table: node_field_data + field: title + relationship: none + group_type: group + admin_label: '' + entity_type: node + entity_field: title + plugin_id: field + label: '' + exclude: false + alter: + alter_text: false + make_link: false + absolute: false + word_boundary: false + ellipsis: false + strip_tags: false + trim: false + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: string + settings: + link_to_entity: true + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + pager: + type: mini + options: + offset: 0 + pagination_heading_level: h4 + items_per_page: 10 + total_pages: null + id: 0 + tags: + next: ›› + previous: ‹‹ + expose: + items_per_page: false + items_per_page_label: 'Items per page' + items_per_page_options: '5, 10, 25, 50' + items_per_page_options_all: false + items_per_page_options_all_label: '- All -' + offset: false + offset_label: Offset + exposed_form: + type: basic + options: + submit_button: Apply + reset_button: false + reset_button_label: Reset + exposed_sorts_label: 'Sort by' + expose_sort_order: true + sort_asc_label: Asc + sort_desc_label: Desc + access: + type: perm + options: + perm: 'access content' + cache: + type: tag + options: { } + empty: { } + sorts: + created: + id: created + table: node_field_data + field: created + relationship: none + group_type: group + admin_label: '' + entity_type: node + entity_field: created + plugin_id: date + order: DESC + expose: + label: '' + field_identifier: '' + exposed: false + granularity: second + arguments: { } + filters: + status: + id: status + table: node_field_data + field: status + entity_type: node + entity_field: status + plugin_id: boolean + value: '1' + group: 1 + expose: + operator: '' + style: + type: default + row: + type: fields + options: + default_field_elements: true + inline: { } + separator: '' + hide_empty: false + query: + type: views_query + options: + query_comment: '' + disable_sql_rewrite: false + distinct: false + replica: false + query_tags: { } + relationships: { } + header: + area: + id: area + table: views + field: area + relationship: none + group_type: group + admin_label: '' + plugin_id: text + empty: false + content: + value: 'Header content body' + format: basic_html + tokenize: false + footer: { } + display_extenders: { } + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url.query_args + - 'user.node_grants:view' + - user.permissions + tags: { } + page_1: + id: page_1 + display_title: Page + display_plugin: page + position: 1 + display_options: + display_extenders: { } + path: test-filter-format-dependencies + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url.query_args + - 'user.node_grants:view' + - user.permissions + tags: { } diff --git a/core/modules/views/tests/src/Functional/Update/FilterFormatDependencyUpdateTest.php b/core/modules/views/tests/src/Functional/Update/FilterFormatDependencyUpdateTest.php new file mode 100644 index 000000000000..b33334e104de --- /dev/null +++ b/core/modules/views/tests/src/Functional/Update/FilterFormatDependencyUpdateTest.php @@ -0,0 +1,42 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\Tests\views\Functional\Update; + +use Drupal\FunctionalTests\Update\UpdatePathTestBase; +use Drupal\views\Entity\View; + +/** + * Tests the upgrade path for fixing dependencies on filter formats. + * + * @group Update + */ +class FilterFormatDependencyUpdateTest extends UpdatePathTestBase { + + /** + * {@inheritdoc} + */ + protected function setDatabaseDumpFiles(): void { + $this->databaseDumpFiles = [ + __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-10.3.0.filled.standard.php.gz', + __DIR__ . '/../../../fixtures/update/test_filter_format_dependencies.php', + ]; + } + + /** + * @covers views_post_update_filter_format_dependencies + */ + public function testViewsFieldPluginConversion(): void { + $view = View::load('test_filter_format_dependencies'); + $data = $view->toArray(); + $this->assertArrayNotHasKey('config', $data['dependencies']); + + $this->runUpdates(); + + $view = View::load('test_filter_format_dependencies'); + $data = $view->toArray(); + $this->assertEquals(['filter.format.basic_html'], $data['dependencies']['config']); + } + +} -- GitLab From 277ad172ba997fa2bdb546be150fd548dedd2f8e Mon Sep 17 00:00:00 2001 From: David Cameron <david@cadeyrn.us> Date: Sat, 22 Mar 2025 23:14:26 -0500 Subject: [PATCH 12/15] phpstan --- core/modules/views/views.post_update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/views/views.post_update.php b/core/modules/views/views.post_update.php index 66acd0cdb80e..a32a0dd8a0d4 100644 --- a/core/modules/views/views.post_update.php +++ b/core/modules/views/views.post_update.php @@ -92,7 +92,7 @@ function views_post_update_table_css_class(?array &$sandbox = NULL): void { /** * Fix views with filter_format dependencies. */ -function views_post_update_filter_format_dependencies() { +function views_post_update_filter_format_dependencies(): void { $views = View::loadMultiple(); array_walk($views, function (View $view) { $old_dependencies = $view->getDependencies(); -- GitLab From e4724d0018e8545f6f1cc4123eb7c5e4a3482bb9 Mon Sep 17 00:00:00 2001 From: David Cameron <david@cadeyrn.us> Date: Sun, 23 Mar 2025 22:42:19 -0500 Subject: [PATCH 13/15] Use ConfigEntityUpdater --- core/modules/views/views.post_update.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/core/modules/views/views.post_update.php b/core/modules/views/views.post_update.php index a32a0dd8a0d4..6acc28f0df16 100644 --- a/core/modules/views/views.post_update.php +++ b/core/modules/views/views.post_update.php @@ -6,7 +6,6 @@ */ use Drupal\Core\Config\Entity\ConfigEntityUpdater; -use Drupal\views\Entity\View; use Drupal\views\ViewEntityInterface; use Drupal\views\ViewsConfigUpdater; @@ -92,13 +91,6 @@ function views_post_update_table_css_class(?array &$sandbox = NULL): void { /** * Fix views with filter_format dependencies. */ -function views_post_update_filter_format_dependencies(): void { - $views = View::loadMultiple(); - array_walk($views, function (View $view) { - $old_dependencies = $view->getDependencies(); - $new_dependencies = $view->calculateDependencies()->getDependencies(); - if ($old_dependencies !== $new_dependencies) { - $view->save(); - } - }); +function views_post_update_filter_format_dependencies(?array &$sandbox = NULL): void { + \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'view'); } -- GitLab From 3fc180ca9ee9000b441a98239afbb00dd0c51a48 Mon Sep 17 00:00:00 2001 From: David Cameron <david@cadeyrn.us> Date: Sun, 23 Mar 2025 23:21:23 -0500 Subject: [PATCH 14/15] Changed post_update name to change update order and prevent deprecation warning --- .../src/Functional/Update/FilterFormatDependencyUpdateTest.php | 2 +- core/modules/views/views.post_update.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/modules/views/tests/src/Functional/Update/FilterFormatDependencyUpdateTest.php b/core/modules/views/tests/src/Functional/Update/FilterFormatDependencyUpdateTest.php index b33334e104de..e0bda47df7bc 100644 --- a/core/modules/views/tests/src/Functional/Update/FilterFormatDependencyUpdateTest.php +++ b/core/modules/views/tests/src/Functional/Update/FilterFormatDependencyUpdateTest.php @@ -25,7 +25,7 @@ protected function setDatabaseDumpFiles(): void { } /** - * @covers views_post_update_filter_format_dependencies + * @covers views_post_update_views_filter_format_dependencies */ public function testViewsFieldPluginConversion(): void { $view = View::load('test_filter_format_dependencies'); diff --git a/core/modules/views/views.post_update.php b/core/modules/views/views.post_update.php index 6acc28f0df16..10bdb2d7309e 100644 --- a/core/modules/views/views.post_update.php +++ b/core/modules/views/views.post_update.php @@ -91,6 +91,6 @@ function views_post_update_table_css_class(?array &$sandbox = NULL): void { /** * Fix views with filter_format dependencies. */ -function views_post_update_filter_format_dependencies(?array &$sandbox = NULL): void { +function views_post_update_views_filter_format_dependencies(?array &$sandbox = NULL): void { \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'view'); } -- GitLab From 9c8b7acef61ff0b48f9adefdcdd2a652556c1550 Mon Sep 17 00:00:00 2001 From: David Cameron <david.cameron@usda.gov> Date: Thu, 27 Mar 2025 15:08:10 -0400 Subject: [PATCH 15/15] Updated views with format dependencies --- .../test_views/views.view.test_entity_translations_link.yml | 2 ++ .../update/views.view.test_entity_id_argument_update.yml | 1 + .../test_views/views.view.test_entity_id_argument.yml | 1 + .../test_views/views.view.test_token_view.yml | 2 ++ .../views_test_config/test_views/views.view.test_tokens.yml | 4 +++- 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/modules/content_translation/tests/modules/content_translation_test_views/test_views/views.view.test_entity_translations_link.yml b/core/modules/content_translation/tests/modules/content_translation_test_views/test_views/views.view.test_entity_translations_link.yml index ffa73e8edef8..cb5f73d89ffc 100644 --- a/core/modules/content_translation/tests/modules/content_translation_test_views/test_views/views.view.test_entity_translations_link.yml +++ b/core/modules/content_translation/tests/modules/content_translation_test_views/test_views/views.view.test_entity_translations_link.yml @@ -1,6 +1,8 @@ langcode: en status: true dependencies: + config: + - filter.format.plain_text module: - content_translation - user diff --git a/core/modules/views/tests/fixtures/update/views.view.test_entity_id_argument_update.yml b/core/modules/views/tests/fixtures/update/views.view.test_entity_id_argument_update.yml index 04081a72149a..696b72c0ccc3 100644 --- a/core/modules/views/tests/fixtures/update/views.view.test_entity_id_argument_update.yml +++ b/core/modules/views/tests/fixtures/update/views.view.test_entity_id_argument_update.yml @@ -4,6 +4,7 @@ status: true dependencies: config: - core.entity_view_mode.node.teaser + - filter.format.basic_html - node.type.article - taxonomy.vocabulary.tags module: diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_id_argument.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_id_argument.yml index adbe58e19404..5fde58622b3b 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_id_argument.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_id_argument.yml @@ -3,6 +3,7 @@ status: true dependencies: config: - core.entity_view_mode.node.teaser + - filter.format.plain_text - node.type.article - taxonomy.vocabulary.tags module: diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_token_view.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_token_view.yml index 7c21d5c01ce1..097336eafee7 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_token_view.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_token_view.yml @@ -1,6 +1,8 @@ langcode: en status: true dependencies: + config: + - filter.format.basic_html module: - node - user diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_tokens.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_tokens.yml index 0d01f95e215f..19cbb51e4757 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_tokens.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_tokens.yml @@ -1,6 +1,8 @@ langcode: en status: true -dependencies: { } +dependencies: + config: + - filter.format.plain_text id: test_tokens label: 'Test tokens' module: views -- GitLab