diff --git a/core/modules/rest/tests/modules/rest_test_views/rest_test_views.install b/core/modules/rest/tests/modules/rest_test_views/rest_test_views.install new file mode 100644 index 0000000000000000000000000000000000000000..edc5a585f84d90980be2d04936dc690aa932184b --- /dev/null +++ b/core/modules/rest/tests/modules/rest_test_views/rest_test_views.install @@ -0,0 +1,21 @@ +<?php + +/** + * @file + * Install function for the Rest Test Views module. + */ + +declare(strict_types=1); + +use Drupal\views\Tests\ViewTestData; + +/** + * Implements hook_install(). + */ +function rest_test_views_install(): void { + + // Install the state and schema by for views test data. + \Drupal::state()->set('views_test_data_schema', ViewTestData::schemaDefinition()); + \Drupal::state()->set('views_test_data_views_data', ViewTestData::viewsData()); + drupal_flush_all_caches(); +} diff --git a/core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_entity.yml b/core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_entity.yml index 9444338650fa0d9d3f02ca7962d40a0c0af6e0a7..8612f65df475c01036c9b669b1eedcc126bd1785 100644 --- a/core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_entity.yml +++ b/core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_entity.yml @@ -2,7 +2,9 @@ langcode: en status: true dependencies: module: + - entity_test - rest + - serialization - user id: test_serializer_display_entity label: 'Test serialize display entity rows' @@ -13,42 +15,60 @@ base_table: entity_test base_field: id display: default: - display_plugin: default id: default display_title: Default + display_plugin: default position: null display_options: + title: 'Test serialize' + exposed_form: + type: basic access: type: perm options: perm: 'access content' cache: type: tag - query: - type: views_query - exposed_form: - type: basic - style: - type: serializer - row: - type: data_entity sorts: id: id: standard table: entity_test field: id - order: DESC - plugin_id: date entity_type: entity_test entity_field: id - title: 'Test serialize' + plugin_id: date + order: DESC arguments: { } + style: + type: serializer + row: + type: data_entity + query: + type: views_query + display_extenders: { } + cache_metadata: + max-age: -1 + contexts: + - entity_test_view_grants + - 'languages:language_interface' + - request_format + - url.query_args + - user.permissions + tags: { } rest_export_1: - display_plugin: rest_export id: rest_export_1 display_title: serializer + display_plugin: rest_export position: null display_options: defaults: access: false + display_extenders: { } path: test/serialize/entity + cache_metadata: + max-age: -1 + contexts: + - entity_test_view_grants + - 'languages:language_interface' + - request_format + tags: { } diff --git a/core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_field.yml b/core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_field.yml index 414de42d6b19f87634eb0153bfdf71daa9b5386a..cac819a387279aee2395db8ab14ad0daa84bb511 100644 --- a/core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_field.yml +++ b/core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_field.yml @@ -3,7 +3,9 @@ status: true dependencies: module: - rest + - serialization - user + - views_test_data id: test_serializer_display_field label: 'Test serializer display field rows' module: rest @@ -13,32 +15,19 @@ base_table: views_test_data base_field: id display: default: - display_plugin: default id: default display_title: Default + display_plugin: default position: null display_options: - access: - type: perm - options: - perm: 'access content' - cache: - type: tag - query: - type: views_query - exposed_form: - type: basic - style: - type: serializer - row: - type: data_field + title: 'Test serialize' fields: name: id: name table: views_test_data field: name - label: '' plugin_id: string + label: '' nothing: id: nothing table: views @@ -56,49 +45,71 @@ display: id: created table: views_test_data field: created - type: timestamp - settings: - date_format: medium - custom_date_format: '' - timezone: '' - plugin_id: field + plugin_id: date + date_format: timestamp + custom_date_format: '' + timezone: '' + exposed_form: + type: basic + access: + type: perm + options: + perm: 'access content' + cache: + type: tag sorts: created: id: created table: views_test_data field: created - order: DESC plugin_id: date - title: 'Test serialize' + order: DESC arguments: { } + style: + type: serializer + row: + type: data_field + query: + type: views_query + display_extenders: { } + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_interface' + - request_format + - url.query_args + - user.permissions + tags: { } rest_export_1: - display_plugin: rest_export id: rest_export_1 display_title: serializer + display_plugin: rest_export position: null display_options: - defaults: - access: false - style: false - row: false - path: test/serialize/field access: type: none style: type: serializer row: type: data_field + defaults: + access: false + style: false + row: false + display_extenders: { } + path: test/serialize/field + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_interface' + - request_format + tags: { } rest_export_2: - display_plugin: rest_export id: rest_export_2 display_title: 'serialize - access denied' + display_plugin: rest_export position: null display_options: - defaults: - access: false - style: false - row: false - path: test/serialize/denied access: type: perm options: @@ -107,3 +118,16 @@ display: type: serializer row: type: data_field + defaults: + access: false + style: false + row: false + display_extenders: { } + path: test/serialize/denied + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_interface' + - request_format + - user.permissions + tags: { } diff --git a/core/modules/views/src/Plugin/ViewsHandlerManager.php b/core/modules/views/src/Plugin/ViewsHandlerManager.php index a8a3fdae9046859e6464792a2b6dfc1981b6651c..8bd3d243c39b215f7ce27c74b52b04a39d26886d 100644 --- a/core/modules/views/src/Plugin/ViewsHandlerManager.php +++ b/core/modules/views/src/Plugin/ViewsHandlerManager.php @@ -105,6 +105,7 @@ public function getHandler(array $item, ?string $override_plugin_id = NULL): Vie } } + // First priority is to use the override. // When aggregation is enabled, particular plugins need to be // replaced in order to override the query with a query that // can run the aggregate counts, sums, or averages for example. @@ -112,13 +113,24 @@ public function getHandler(array $item, ?string $override_plugin_id = NULL): Vie // for example which aggressively overrides any filter used // by a number of mathematical-type queries regardless of the // original filter. - $plugin_id = $override_plugin_id ?: $definition['id']; - // Try to use the overridden handler. - $handler = $this->createInstance($plugin_id, $definition); - if ($override_plugin_id && method_exists($handler, 'broken') && $handler->broken()) { - $handler = $this->createInstance($definition['id'], $definition); + if ($override_plugin_id) { + $handler = $this->createInstance($override_plugin_id, $definition); + if (!method_exists($handler, 'broken') || !$handler->broken()) { + return $handler; + } } - return $handler; + + // Then try the configuration provided for the handler. + if (isset($item['plugin_id'])) { + $handler = $this->createInstance($item['plugin_id'], $definition); + if (!method_exists($handler, 'broken') || !$handler->broken()) { + return $handler; + } + } + + // Finally, fall back to the default configuration suggested + // by the view data. + return $this->createInstance($definition['id'], $definition); } // Finally, use the 'broken' handler. diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_block_exposed_ajax.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_block_exposed_ajax.yml index 649b5fe8abdef6223e4f45f8bf4745cfe8d0090e..69e49097ad171be7d6e9d341430df496964be44e 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_block_exposed_ajax.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_block_exposed_ajax.yml @@ -35,7 +35,7 @@ display: field: type id: type table: node_field_data - plugin_id: in_operator + plugin_id: bundle entity_type: node entity_field: type pager: diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_block_exposed_ajax_with_page.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_block_exposed_ajax_with_page.yml index c484c6b1389e7f4225c698245e928d4b7d191a15..ab6321d8b6f2c5dfa07e993d743f21d6c2b6469b 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_block_exposed_ajax_with_page.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_block_exposed_ajax_with_page.yml @@ -35,7 +35,7 @@ display: field: type id: type table: node_field_data - plugin_id: in_operator + plugin_id: bundle entity_type: node entity_field: type pager: diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_click_sort.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_click_sort.yml index 3ab5ecb6689400b5276c6c0e3ad40cf78bb0c62f..5aaa351c1ae212d8597bc53d2555e2456fa27522 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_click_sort.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_click_sort.yml @@ -1,40 +1,44 @@ langcode: en status: true -dependencies: { } +dependencies: + module: + - user + - views_test_data id: test_click_sort label: test_click_sort module: views description: '' tag: '' base_table: views_test_data -base_field: nid +base_field: id display: default: + id: default + display_title: Default + display_plugin: default + position: null display_options: fields: id: id: id table: views_test_data field: id - label: ID plugin_id: numeric + label: ID name: id: name table: views_test_data field: name - label: Name plugin_id: string + label: '' created: id: created table: views_test_data field: created - label: created - plugin_id: field - type: timestamp - settings: - date_format: medium - custom_date_format: '' - timezone: '' + plugin_id: date + date_format: timestamp + custom_date_format: '' + timezone: '' access: type: none cache: @@ -51,14 +55,17 @@ display: default_sort_order: desc created: sortable: false - display_plugin: default - display_title: Default - id: default - position: 0 + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_interface' + - url.query_args + - user.permissions + tags: { } page_1: - display_options: - path: test_click_sort - display_plugin: page - display_title: Page id: page_1 + display_title: Page + display_plugin: page position: 0 + display_options: + path: test_click_sort diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_click_sort_ajax.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_click_sort_ajax.yml index bf65e0eaf3792bbbee1adb48e84b8b9eb682dcc8..534e3eaecbac31566b6ae2b69289be3b0a1cb5d5 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_click_sort_ajax.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_click_sort_ajax.yml @@ -1,41 +1,105 @@ langcode: en status: true -dependencies: { } +dependencies: + module: + - views_test_data id: test_click_sort_ajax label: test_click_sort_ajax module: views description: '' tag: '' base_table: views_test_data -base_field: nid +base_field: id display: default: + id: default + display_title: Default + display_plugin: default + position: null display_options: - use_ajax: true fields: id: id: id table: views_test_data field: id - label: ID plugin_id: numeric + label: ID name: id: name table: views_test_data field: name - label: Name + relationship: none + group_type: group + admin_label: '' plugin_id: string + label: Name + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true created: id: created table: views_test_data field: created - label: created - plugin_id: field - type: timestamp - settings: - date_format: medium - custom_date_format: '' - timezone: '' + plugin_id: date + date_format: timestamp + custom_date_format: '' + timezone: '' + pager: + type: mini + options: + offset: 0 + pagination_heading_level: h4 + items_per_page: 1 + total_pages: null + id: 0 + tags: + next: 'Next ›' + previous: '‹ 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 access: type: none cache: @@ -43,23 +107,61 @@ display: style: type: table options: + grouping: { } + row_class: '' + default_row_class: true + columns: + id: id + name: name + created: created + default: id info: id: - sortable: true + sortable: false default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' name: sortable: true default_sort_order: desc + align: '' + separator: '' + empty_column: false + responsive: '' created: sortable: false - display_plugin: default - display_title: Default - id: default - position: 0 + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + override: true + sticky: false + summary: '' + empty_table: false + caption: '' + description: '' + use_ajax: true + display_extenders: { } + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_interface' + - url.query_args + tags: { } page_1: - display_options: - path: test_click_sort - display_plugin: page - display_title: Page id: page_1 + display_title: Page + display_plugin: page position: 0 + display_options: + display_extenders: { } + path: test_click_sort + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_interface' + - url.query_args + tags: { } diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_test_protected_access.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_test_protected_access.yml index a41124d71e84c327c5fa4388fb944ffb746c6831..1a3bf61bc6880f14eee9aaed5122bb2dc02d7029 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_test_protected_access.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_entity_test_protected_access.yml @@ -86,7 +86,7 @@ display: exclude: false entity_type: entity_test entity_field: test_text_access - plugin_id: standard + plugin_id: field empty: '' hide_empty: false empty_zero: false diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_block.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_block.yml index 2df02b0b6633756e16b957d4fffc8cbefef3d1c1..ebcf5c9f704d4f81eda759d7869344259a96df3c 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_block.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_block.yml @@ -1,6 +1,8 @@ langcode: en status: true dependencies: + config: + - core.entity_view_mode.node.teaser module: - node id: test_exposed_block @@ -12,66 +14,83 @@ base_table: node_field_data base_field: nid display: default: + id: default + display_title: Default + display_plugin: default + position: 0 display_options: title: 'Test Exposed Block' + pager: + type: full + exposed_form: + type: basic + options: + reset_button: true access: type: none cache: type: tag - exposed_form: - options: - reset_button: true - type: basic filters: type: - expose: - identifier: type - label: 'Content: Type' - operator_id: type_op - reduce: false - exposed: true - field: type id: type table: node_field_data - plugin_id: in_operator + field: type entity_type: node entity_field: type - pager: - type: full - query: - options: - query_comment: '' - type: views_query + plugin_id: bundle + exposed: true + expose: + operator_id: type_op + label: 'Content: Type' + identifier: type + reduce: false style: type: default row: type: 'entity:node' - display_plugin: default - display_title: Default - id: default - position: 0 - page_1: - display_options: - path: test_exposed_block - exposed_block: true - display_plugin: page - display_title: Page - id: page_1 - position: 0 + query: + type: views_query + options: + query_comment: '' + display_extenders: { } + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_interface' + - url + - url.query_args + - 'user.node_grants:view' + tags: { } block_1: - display_plugin: block id: block_1 display_title: Block + display_plugin: block position: 2 display_options: + exposed_block: true display_extenders: { } + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_interface' + - url + - url.query_args + - 'user.node_grants:view' + tags: { } + page_1: + id: page_1 + display_title: Page + display_plugin: page + position: 0 + display_options: exposed_block: true + display_extenders: { } + path: test_exposed_block cache_metadata: max-age: -1 contexts: - - 'languages:language_content' - 'languages:language_interface' + - url - url.query_args - 'user.node_grants:view' - - user.permissions tags: { } diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_form_buttons.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_form_buttons.yml index 9a3605845e80e46b34f856d3184f085471616c51..89b658d11dc30deecb6fcc92ac212ff7ba932d4a 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_form_buttons.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_form_buttons.yml @@ -1,6 +1,8 @@ langcode: en status: true dependencies: + config: + - core.entity_view_mode.node.teaser module: - node id: test_exposed_form_buttons @@ -12,48 +14,66 @@ base_table: node_field_data base_field: nid display: default: + id: default + display_title: Default + display_plugin: default + position: 0 display_options: + pager: + type: full + exposed_form: + type: basic + options: + reset_button: true access: type: none cache: type: tag - exposed_form: - options: - reset_button: true - type: basic filters: type: - expose: - identifier: type - label: 'Content: Type' - operator_id: type_op - reduce: false - description: 'Exposed description' - exposed: true - field: type id: type table: node_field_data - plugin_id: in_operator + field: type entity_type: node entity_field: type - pager: - type: full - query: - options: - query_comment: '' - type: views_query + plugin_id: bundle + exposed: true + expose: + operator_id: type_op + label: 'Content: Type' + description: 'Exposed description' + identifier: type + reduce: false style: type: default row: type: 'entity:node' - display_plugin: default - display_title: Default - id: default - position: 0 + query: + type: views_query + options: + query_comment: '' + display_extenders: { } + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_interface' + - url + - url.query_args + - 'user.node_grants:view' + tags: { } page_1: - display_options: - path: test_exposed_form_buttons - display_plugin: page - display_title: Page id: page_1 + display_title: Page + display_plugin: page position: 0 + display_options: + display_extenders: { } + path: test_exposed_form_buttons + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_interface' + - url + - url.query_args + - 'user.node_grants:view' + tags: { } diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_form_checkboxes.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_form_checkboxes.yml index a61c0adb625c1e519307119c4c4ff57605b7a87c..bd45360bc7b97beaf7cb36016b7a2cc52c3045ea 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_form_checkboxes.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_form_checkboxes.yml @@ -2,7 +2,8 @@ langcode: en status: true dependencies: config: - - taxonomy.vocabulary.test_exposed_checkboxes + - core.entity_view_mode.node.teaser + - taxonomy.vocabulary.tags module: - node - taxonomy @@ -15,33 +16,44 @@ base_table: node_field_data base_field: nid display: default: + id: default + display_title: Default + display_plugin: default + position: 0 display_options: + pager: + type: full + exposed_form: + type: basic + options: + reset_button: true access: type: none cache: type: tag - exposed_form: - options: - reset_button: true - type: basic filters: - type: - id: type + type_1: + id: type_1 table: node_field_data field: type relationship: none group_type: group admin_label: '' + entity_type: node + entity_field: type + plugin_id: bundle operator: in value: { } group: 1 exposed: true expose: - operator_id: type_op - label: 'Content: Type' - description: 'Exposed description' + operator_id: type_1_op + label: 'Content type' + description: '' use_operator: false - operator: '' + operator: type_1_op + operator_limit_selection: false + operator_list: { } identifier: type required: false remember: false @@ -49,6 +61,7 @@ display: remember_roles: authenticated: authenticated anonymous: '0' + content_editor: '0' administrator: '0' reduce: false is_grouped: false @@ -63,9 +76,6 @@ display: default_group: All default_group_multiple: { } group_items: { } - plugin_id: in_operator - entity_type: node - entity_field: type tid: id: tid table: taxonomy_index @@ -73,6 +83,7 @@ display: relationship: none group_type: group admin_label: '' + plugin_id: taxonomy_index_tid operator: and value: { } group: 1 @@ -83,6 +94,8 @@ display: description: '' use_operator: false operator: tid_op + operator_limit_selection: false + operator_list: { } identifier: tid required: false remember: false @@ -105,50 +118,45 @@ display: default_group_multiple: { } group_items: { } reduce_duplicates: false + vid: tags type: select - limit: true - vid: test_exposed_checkboxes hierarchy: false + limit: true error_message: true - plugin_id: taxonomy_index_tid - pager: - type: full - query: - options: - query_comment: '' - type: views_query + filter_groups: + operator: AND + groups: + 1: AND style: type: default row: type: 'entity:node' + query: + type: views_query + options: + query_comment: '' display_extenders: { } - display_plugin: default - display_title: Default - id: default - position: 0 cache_metadata: max-age: -1 contexts: - 'languages:language_interface' - url - url.query_args - - user - 'user.node_grants:view' tags: { } page_1: - display_options: - path: test_exposed_form_checkboxes - display_extenders: { } - display_plugin: page - display_title: Page id: page_1 + display_title: Page + display_plugin: page position: 0 + display_options: + display_extenders: { } + path: test_exposed_form_checkboxes cache_metadata: max-age: -1 contexts: - 'languages:language_interface' - url - url.query_args - - user - 'user.node_grants:view' tags: { } diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_form_pager.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_form_pager.yml index d091ef6762228b06692b037a68d4147b9c7a8251..c6565810be25efdb57a0519b669bb4f2646b5da0 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_form_pager.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_exposed_form_pager.yml @@ -62,7 +62,7 @@ display: default_group: All default_group_multiple: { } group_items: { } - plugin_id: in_operator + plugin_id: bundle entity_type: node entity_field: type created: diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_filter_in_operator_ui.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_filter_in_operator_ui.yml index 44177e0e186a9e3241fc5b8665fc5567a9eb8cde..3299d7ea86ad5e098f2f743ad1a8251674800e24 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_filter_in_operator_ui.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_filter_in_operator_ui.yml @@ -63,7 +63,7 @@ display: field: type id: type table: node_field_data - plugin_id: in_operator + plugin_id: bundle entity_type: node entity_field: type nid: diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_history.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_history.yml index c2b25fff96970d27d332d644672b835ea28b1697..d67f17051828080cee04ea9f20aef348bb4cf008 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_history.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_history.yml @@ -188,8 +188,7 @@ display: group_type: group admin_label: '' operator: '=' - value: - value: '' + value: '' group: 1 exposed: false expose: @@ -216,7 +215,7 @@ display: default_group: All default_group_multiple: { } group_items: { } - plugin_id: date + plugin_id: history_user_timestamp defaults: filters: false filter_groups: false diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_remember_selected.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_remember_selected.yml index 11b3ceec29c21f471749820eca83e26f3f9e735c..6113f4337fad0f7efc4a242f96d57692d1c7537f 100644 --- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_remember_selected.yml +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_remember_selected.yml @@ -40,7 +40,7 @@ display: admin_label: '' entity_type: node entity_field: type - plugin_id: in_operator + plugin_id: bundle operator: in value: { } group: 1 diff --git a/core/modules/views/tests/modules/views_test_data_alter/src/Hook/ViewsTestDataAlterHooks.php b/core/modules/views/tests/modules/views_test_data_alter/src/Hook/ViewsTestDataAlterHooks.php new file mode 100644 index 0000000000000000000000000000000000000000..c62ef3f64125dd2326fb3e3545bc066ebbcf8259 --- /dev/null +++ b/core/modules/views/tests/modules/views_test_data_alter/src/Hook/ViewsTestDataAlterHooks.php @@ -0,0 +1,23 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\views_test_data_alter\Hook; + +use Drupal\Core\Hook\Attribute\Hook; + +class ViewsTestDataAlterHooks { + + /** + * Implements hook_views_data_alter(). + */ + #[Hook('views_data_alter')] + public function viewsDataAlter(array &$data): void { + // Modify a filter to use a different filter handler plugin + // by default so that we can test that the handler used + // respects the handler plugin ID specified in the + // configuration. + $data['node_field_data']['status']['filter']['id'] = 'numeric'; + } + +} diff --git a/core/modules/views/tests/modules/views_test_data_alter/views_test_data_alter.info.yml b/core/modules/views/tests/modules/views_test_data_alter/views_test_data_alter.info.yml new file mode 100644 index 0000000000000000000000000000000000000000..ac3d0bbb1217bf419672cb139d4d6064583ac357 --- /dev/null +++ b/core/modules/views/tests/modules/views_test_data_alter/views_test_data_alter.info.yml @@ -0,0 +1,7 @@ +name: 'Views Test Data Alter' +type: module +description: 'Test module for Views to alter data.' +package: Testing +version: VERSION +dependencies: + - drupal:views diff --git a/core/modules/views/tests/src/Functional/Entity/BaseFieldAccessTest.php b/core/modules/views/tests/src/Functional/Entity/BaseFieldAccessTest.php index 8ee795e5b60e344900ff3a029f3c3e59fc0e6fa8..14b713d8cd587390aa04d74a82bc08ee0f07b619 100644 --- a/core/modules/views/tests/src/Functional/Entity/BaseFieldAccessTest.php +++ b/core/modules/views/tests/src/Functional/Entity/BaseFieldAccessTest.php @@ -39,15 +39,6 @@ class BaseFieldAccessTest extends ViewTestBase { protected function setUp($import_test_views = TRUE, $modules = ['views_test_config', 'comment_test_views']): void { parent::setUp($import_test_views, $modules); - \Drupal::state()->set('entity_test.views_data', [ - 'entity_test' => [ - 'test_text_access' => [ - 'field' => [ - 'id' => 'standard', - ], - ], - ], - ]); $entity_1 = EntityTest::create([ 'test_text_access' => 'no access value', ]); diff --git a/core/modules/views/tests/src/Functional/Handler/HandlerTest.php b/core/modules/views/tests/src/Functional/Handler/HandlerTest.php index fa9af239ca3eb248913402ec437994ea2d3b507e..c6523c40c10042689b64830361db2f2c84220579 100644 --- a/core/modules/views/tests/src/Functional/Handler/HandlerTest.php +++ b/core/modules/views/tests/src/Functional/Handler/HandlerTest.php @@ -333,6 +333,12 @@ public function testSetRelationship(): void { * @see \Drupal\views\Plugin\views\HandlerBase::placeholder() */ public function testPlaceholder(): void { + // Change the test view to use the test field plugin which has the + // additional get placeholder method. + $config = $this->config('views.view.test_view'); + $config->set('display.default.display_options.fields.name.plugin_id', 'test_field'); + $config->save(); + $view = Views::getView('test_view'); $view->initHandlers(); $view->initQuery(); @@ -342,7 +348,7 @@ public function testPlaceholder(): void { $field = $handler->field; $string = ':' . $table . '_' . $field; - // Make sure the placeholder variables are like expected. + // Make sure the placeholder variables contain the expected values. $this->assertEquals($string, $handler->getPlaceholder()); $this->assertEquals($string . 1, $handler->getPlaceholder()); $this->assertEquals($string . 2, $handler->getPlaceholder()); @@ -369,7 +375,7 @@ public function testAccess(): void { $views_data = $this->viewsData(); $views_data = $views_data['views_test_data']; - // Enable access to callback only field and deny for callback + arguments. + // Enable access only to the callback field and deny access for the callback and the arguments. $this->config('views_test_data.tests')->set('handler_access_callback', TRUE)->save(); $this->config('views_test_data.tests')->set('handler_access_callback_argument', FALSE)->save(); $view->initDisplay(); @@ -382,7 +388,7 @@ public function testAccess(): void { } } - // Enable access to the callback + argument handlers and deny for callback. + // Enable access to the callback and the argument handlers and deny access for the callback. $this->config('views_test_data.tests')->set('handler_access_callback', FALSE)->save(); $this->config('views_test_data.tests')->set('handler_access_callback_argument', TRUE)->save(); $view->destroy(); diff --git a/core/modules/views/tests/src/Functional/Plugin/ExposedFormCheckboxesTest.php b/core/modules/views/tests/src/Functional/Plugin/ExposedFormCheckboxesTest.php index a6e39524c245ced4ac1967b3ba8384f1c127f227..a5b1b27db056bd57f6565b51aee4fc4eecda788c 100644 --- a/core/modules/views/tests/src/Functional/Plugin/ExposedFormCheckboxesTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/ExposedFormCheckboxesTest.php @@ -61,7 +61,7 @@ protected function setUp($import_test_views = TRUE, $modules = []): void { // vocabulary is in place to meet the view dependencies. $vocabulary = Vocabulary::create([ 'name' => 'test_exposed_checkboxes', - 'vid' => 'test_exposed_checkboxes', + 'vid' => 'tags', 'nodes' => ['article' => 'article'], ]); $vocabulary->save(); diff --git a/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php b/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php index fa9995eea82ee2e04fe4756b14cbeaaf8df4372a..933554003ff0c5dcf19b78561ff42e5516240c03 100644 --- a/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php @@ -116,7 +116,7 @@ public function testExposedIdentifier(): void { 'field' => 'type', 'id' => 'type', 'table' => 'node_field_data', - 'plugin_id' => 'in_operator', + 'plugin_id' => 'bundle', 'entity_type' => 'node', 'entity_field' => 'type', 'expose' => [ diff --git a/core/modules/views/tests/src/Kernel/Handler/FieldTimeIntervalTest.php b/core/modules/views/tests/src/Kernel/Handler/FieldTimeIntervalTest.php index 9f4d930c6f780d8896860b84d6abb6b01e15baae..25f1db02ecc16eab11b3134e4ce11e5c313349a3 100644 --- a/core/modules/views/tests/src/Kernel/Handler/FieldTimeIntervalTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/FieldTimeIntervalTest.php @@ -44,13 +44,16 @@ class FieldTimeIntervalTest extends ViewsKernelTestBase { * Tests the TimeInterval handler. */ public function testFieldTimeInterval(): void { - $view = Views::getView('test_view'); - $view->setDisplay(); - $this->executeView($view); - foreach ($view->result as $delta => $row) { + $view_config = $this->config('views.view.test_view'); + $view_config->set('display.default.display_options.fields.age.plugin_id', 'time_interval'); + foreach (array_keys($this->ages) as $delta) { [, $formatted_value, $granularity] = $this->ages[$delta]; - $view->field['age']->options['granularity'] = $granularity; - $this->assertEquals($formatted_value, $view->field['age']->advancedRender($row)); + $view_config->set('display.default.display_options.fields.age.granularity', $granularity); + $view_config->save(); + $view = Views::getView('test_view'); + $view->setDisplay(); + $this->executeView($view); + $this->assertEquals($formatted_value, $view->field['age']->advancedRender($view->result[$delta])); } } diff --git a/core/modules/views/tests/src/Kernel/ModuleTest.php b/core/modules/views/tests/src/Kernel/ModuleTest.php index b3cdf6446d9deebeabf4f64ecd2d932bbdbdef7d..ff2d42e327e8b7f6670831a7011223f7d8d601ec 100644 --- a/core/modules/views/tests/src/Kernel/ModuleTest.php +++ b/core/modules/views/tests/src/Kernel/ModuleTest.php @@ -8,6 +8,7 @@ use Drupal\Core\Form\FormState; use Drupal\views\Plugin\views\area\Broken as BrokenArea; use Drupal\views\Plugin\views\field\Broken as BrokenField; +use Drupal\views\Plugin\views\filter\BooleanOperator; use Drupal\views\Plugin\views\filter\Broken as BrokenFilter; use Drupal\views\Plugin\views\filter\Standard; use Drupal\views\Plugin\views\ViewsHandlerInterface; @@ -25,12 +26,12 @@ class ModuleTest extends ViewsKernelTestBase { * * @var array */ - public static $testViews = ['test_view_status', 'test_view', 'test_argument']; + public static $testViews = ['test_view_status', 'test_view', 'test_argument', 'test_redirect_view']; /** * {@inheritdoc} */ - protected static $modules = ['field', 'user', 'block']; + protected static $modules = ['field', 'user', 'block', 'node', 'views_test_data_alter']; /** * Stores the last triggered error. @@ -109,6 +110,14 @@ public function testViewsGetHandler(): void { ]; $handler = $this->container->get('plugin.manager.views.filter')->getHandler($item, 'standard'); $this->assertInstanceOf(Standard::class, $handler); + + // Test that the configuration is respected rather than overridden + // by views data. Using assertSame() here to make the error more clearly + // show what the result is when an error is caused. + $test_view_config = $this->config('views.view.test_redirect_view'); + $item = $test_view_config->get('display.default.display_options.filters.status'); + $handler = $this->container->get('plugin.manager.views.filter')->getHandler($item); + $this->assertSame(BooleanOperator::class, get_class($handler)); } /** diff --git a/core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php b/core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php index 97d670634b3f6f7e9986f94ea283a1120f288181..fa4969d1e9b6d6a43cd80a42e91f496eda86208d 100644 --- a/core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/ExposedFormRenderTest.php @@ -5,8 +5,12 @@ namespace Drupal\Tests\views\Kernel\Plugin; use Drupal\Component\Utility\Html; +use Drupal\Core\Form\FormState; +use Drupal\Core\Path\CurrentPathStack; use Drupal\node\Entity\NodeType; use Drupal\Tests\views\Kernel\ViewsKernelTestBase; +use Drupal\views\ExposedFormCache; +use Drupal\views\Form\ViewsExposedForm; use Drupal\views\Views; /** @@ -20,7 +24,7 @@ class ExposedFormRenderTest extends ViewsKernelTestBase { /** * {@inheritdoc} */ - public static $testViews = ['test_exposed_form_buttons']; + public static $testViews = ['test_exposed_form_buttons', 'test_exposed_admin_ui']; /** * {@inheritdoc} @@ -64,85 +68,38 @@ public function testExposedFormRawInput(): void { 'name' => 'Article', ])->save(); - $view = Views::getView('test_exposed_form_buttons'); + // Build the form state. + $form = []; + $view = Views::getView('test_exposed_admin_ui'); $view->setDisplay(); - $view->displayHandlers->get('default')->overrideOption('filters', [ - 'type' => [ - 'exposed' => TRUE, - 'field' => 'type', - 'id' => 'type', - 'table' => 'node_field_data', - 'plugin_id' => 'in_operator', - 'entity_type' => 'node', - 'entity_field' => 'type', - 'expose' => [ - 'identifier' => 'type', - 'label' => 'Content: Type', - 'operator_id' => 'type_op', - 'reduce' => FALSE, - 'multiple' => FALSE, - ], - ], - 'type_with_default_value' => [ - 'exposed' => TRUE, - 'field' => 'type', - 'id' => 'type_with_default_value', - 'table' => 'node_field_data', - 'plugin_id' => 'in_operator', - 'entity_type' => 'node', - 'entity_field' => 'type', - 'value' => ['article', 'article'], - 'expose' => [ - 'identifier' => 'type_with_default_value', - 'label' => 'Content: Type with value', - 'operator_id' => 'type_op', - 'reduce' => FALSE, - 'multiple' => FALSE, - ], - ], - 'multiple_types' => [ - 'exposed' => TRUE, - 'field' => 'type', - 'id' => 'multiple_types', - 'table' => 'node_field_data', - 'plugin_id' => 'in_operator', - 'entity_type' => 'node', - 'entity_field' => 'type', - 'expose' => [ - 'identifier' => 'multiple_types', - 'label' => 'Content: Type (multiple)', - 'operator_id' => 'type_op', - 'reduce' => FALSE, - 'multiple' => TRUE, - ], - ], - 'multiple_types_with_default_value' => [ - 'exposed' => TRUE, - 'field' => 'type', - 'id' => 'multiple_types_with_default_value', - 'table' => 'node_field_data', - 'plugin_id' => 'in_operator', - 'entity_type' => 'node', - 'entity_field' => 'type', - 'value' => ['article', 'article'], - 'expose' => [ - 'identifier' => 'multiple_types_with_default_value', - 'label' => 'Content: Type with default value (multiple)', - 'operator_id' => 'type_op', - 'reduce' => FALSE, - 'multiple' => TRUE, - ], - ], - ]); - $view->save(); $this->executeView($view); + $form_state = new FormState(); + $form_state->set('view', $view); + $form_state->setValue('type', 'article'); + + // Mock the exposed form. + $exposed_form_cache = $this->createMock(ExposedFormCache::class); + $current_path_stack = $this->createMock(CurrentPathStack::class); + $exposed_form = new ViewsExposedForm($exposed_form_cache, $current_path_stack); + $exposed_form->submitForm($form, $form_state); + $updated_view = $form_state->get('view'); + $expected = [ - 'type' => 'All', - 'type_with_default_value' => 'article', - 'multiple_types_with_default_value' => ['article' => 'article'], + 'type' => 'article', + ]; + $this->assertSame($updated_view->exposed_raw_input, $expected); + + $form_state->setValue('type', ['article', 'page']); + $exposed_form->submitForm($form, $form_state); + $updated_view = $form_state->get('view'); + $expected = [ + 'type' => [ + 'article', + 'page', + ], ]; - $this->assertSame($view->exposed_raw_input, $expected); + $this->assertSame($updated_view->exposed_raw_input, $expected); } }