Skip to content
Snippets Groups Projects
Commit b9a10a16 authored by catch's avatar catch
Browse files

Issue #3458099 by scott_euser, catch, oily, smustgrave, nicxvan: Views handler...

Issue #3458099 by scott_euser, catch, oily, smustgrave, nicxvan: Views handler loading should respect configuration
parent 38de8a6c
No related branches found
No related tags found
No related merge requests found
Showing
with 469 additions and 210 deletions
<?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();
}
......@@ -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: { }
......@@ -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: { }
......@@ -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.
......
......@@ -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:
......
......@@ -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:
......
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
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: { }
......@@ -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
......
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: { }
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: { }
......@@ -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: { }
......@@ -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:
......
......@@ -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:
......
......@@ -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
......
......@@ -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
......
<?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';
}
}
name: 'Views Test Data Alter'
type: module
description: 'Test module for Views to alter data.'
package: Testing
version: VERSION
dependencies:
- drupal:views
......@@ -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',
]);
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment