Issue #3131126 by acbramley, msuthars, tanubansal, Kristen Pol, jungle: Can't show 'revision author' on Block content views
parent
b66f4f1923
commit
97f1ca5672
|
@ -50,6 +50,13 @@ class BlockContentViewsData extends EntityViewsData {
|
|||
$data['block_content_field_revision']['revision_id']['relationship']['title'] = $this->t('Block Content');
|
||||
$data['block_content_field_revision']['revision_id']['relationship']['label'] = $this->t('Get the actual block content from a block content revision.');
|
||||
|
||||
$data['block_content_revision']['revision_user']['help'] = $this->t('The user who created the revision.');
|
||||
$data['block_content_revision']['revision_user']['relationship']['label'] = $this->t('revision user');
|
||||
$data['block_content_revision']['revision_user']['filter']['id'] = 'user_name';
|
||||
|
||||
$data['block_content_revision']['table']['join']['block_content_field_data']['left_field'] = 'revision_id';
|
||||
$data['block_content_revision']['table']['join']['block_content_field_data']['field'] = 'revision_id';
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,324 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- block_content
|
||||
- user
|
||||
id: test_block_content_revision_user
|
||||
label: 'Test block content revision user'
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: block_content_field_data
|
||||
base_field: id
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: 0
|
||||
display_options:
|
||||
access:
|
||||
type: perm
|
||||
options:
|
||||
perm: 'access content'
|
||||
cache:
|
||||
type: tag
|
||||
options: { }
|
||||
query:
|
||||
type: views_query
|
||||
options:
|
||||
disable_sql_rewrite: false
|
||||
distinct: false
|
||||
replica: false
|
||||
query_comment: ''
|
||||
query_tags: { }
|
||||
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
|
||||
pager:
|
||||
type: none
|
||||
options:
|
||||
offset: 0
|
||||
style:
|
||||
type: default
|
||||
options:
|
||||
grouping: { }
|
||||
row_class: ''
|
||||
default_row_class: true
|
||||
uses_fields: false
|
||||
row:
|
||||
type: fields
|
||||
options:
|
||||
inline: { }
|
||||
separator: ''
|
||||
hide_empty: false
|
||||
default_field_elements: true
|
||||
fields:
|
||||
id:
|
||||
id: id
|
||||
table: block_content_field_revision
|
||||
field: id
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: ''
|
||||
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: 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: number_integer
|
||||
settings:
|
||||
thousand_separator: ''
|
||||
prefix_suffix: false
|
||||
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
|
||||
entity_type: block_content
|
||||
entity_field: id
|
||||
plugin_id: field
|
||||
revision_id:
|
||||
id: revision_id
|
||||
table: block_content_field_revision
|
||||
field: revision_id
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: ''
|
||||
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: 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: number_integer
|
||||
settings:
|
||||
thousand_separator: ''
|
||||
prefix_suffix: false
|
||||
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
|
||||
entity_type: block_content
|
||||
entity_field: revision_id
|
||||
plugin_id: field
|
||||
revision_user:
|
||||
id: revision_user
|
||||
table: block_content_revision
|
||||
field: revision_user
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: ''
|
||||
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: 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: target_id
|
||||
type: entity_reference_label
|
||||
settings:
|
||||
link: false
|
||||
group_column: target_id
|
||||
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
|
||||
entity_type: block_content
|
||||
entity_field: revision_user
|
||||
plugin_id: field
|
||||
filters:
|
||||
revision_user:
|
||||
id: revision_user
|
||||
table: block_content_revision
|
||||
field: revision_user
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
operator: in
|
||||
value: { }
|
||||
group: 1
|
||||
exposed: true
|
||||
expose:
|
||||
operator_id: revision_user_op
|
||||
label: 'Revision user'
|
||||
description: ''
|
||||
use_operator: false
|
||||
operator: revision_user_op
|
||||
operator_limit_selection: false
|
||||
operator_list: { }
|
||||
identifier: revision_user
|
||||
required: false
|
||||
remember: false
|
||||
multiple: false
|
||||
remember_roles:
|
||||
authenticated: authenticated
|
||||
anonymous: '0'
|
||||
administrator: '0'
|
||||
reduce: false
|
||||
is_grouped: false
|
||||
group_info:
|
||||
label: ''
|
||||
description: ''
|
||||
identifier: ''
|
||||
optional: true
|
||||
widget: select
|
||||
multiple: false
|
||||
remember: false
|
||||
default_group: All
|
||||
default_group_multiple: { }
|
||||
group_items: { }
|
||||
entity_type: block_content
|
||||
entity_field: revision_user
|
||||
plugin_id: user_name
|
||||
sorts: { }
|
||||
header: { }
|
||||
footer: { }
|
||||
empty: { }
|
||||
relationships: { }
|
||||
arguments: { }
|
||||
display_extenders: { }
|
||||
filter_groups:
|
||||
operator: AND
|
||||
groups: { }
|
||||
cache_metadata:
|
||||
max-age: -1
|
||||
contexts:
|
||||
- 'languages:language_content'
|
||||
- 'languages:language_interface'
|
||||
- url
|
||||
- 'user.block_content_grants:view'
|
||||
- user.permissions
|
||||
tags: { }
|
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\block_content\Kernel\Views;
|
||||
|
||||
use Drupal\block_content\Entity\BlockContent;
|
||||
use Drupal\block_content\Entity\BlockContentType;
|
||||
use Drupal\Tests\user\Traits\UserCreationTrait;
|
||||
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
|
||||
use Drupal\views\Tests\ViewResultAssertionTrait;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the block_content_revision_user field.
|
||||
*
|
||||
* @group block_content
|
||||
*/
|
||||
class RevisionUserTest extends ViewsKernelTestBase {
|
||||
|
||||
use UserCreationTrait;
|
||||
use ViewResultAssertionTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = [
|
||||
'block_content',
|
||||
'block_content_test_views',
|
||||
'system',
|
||||
'user',
|
||||
'views',
|
||||
];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_block_content_revision_user'];
|
||||
|
||||
/**
|
||||
* Map column names.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $columnMap = [
|
||||
'id' => 'id',
|
||||
'revision_id' => 'revision_id',
|
||||
'revision_user' => 'revision_user',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp($import_test_views = TRUE): void {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->installEntitySchema('block_content');
|
||||
$this->installEntitySchema('user');
|
||||
|
||||
if ($import_test_views) {
|
||||
ViewTestData::createTestViews(get_class($this), ['block_content_test_views']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the block_content_revision_user relationship.
|
||||
*/
|
||||
public function testRevisionUser() {
|
||||
$primary_author = $this->createUser();
|
||||
$secondary_author = $this->createUser();
|
||||
|
||||
$block_content_type = BlockContentType::create([
|
||||
'id' => 'basic',
|
||||
'label' => 'basic block',
|
||||
]);
|
||||
$block_content_type->save();
|
||||
|
||||
$block_content = BlockContent::create([
|
||||
'info' => 'Test block content',
|
||||
'type' => 'basic',
|
||||
]);
|
||||
$block_content->setRevisionUserId($primary_author->id());
|
||||
$block_content->save();
|
||||
|
||||
$view = Views::getView('test_block_content_revision_user');
|
||||
$this->executeView($view);
|
||||
$this->assertIdenticalResultset($view, [
|
||||
[
|
||||
'id' => 1,
|
||||
'revision_id' => 1,
|
||||
'revision_user' => $primary_author->id(),
|
||||
],
|
||||
], static::$columnMap);
|
||||
|
||||
// Test results shows the revision author.
|
||||
$block_content->setRevisionUser($secondary_author);
|
||||
$block_content->setNewRevision();
|
||||
$block_content->save();
|
||||
|
||||
$view = Views::getView('test_block_content_revision_user');
|
||||
$this->executeView($view);
|
||||
$this->assertIdenticalResultset($view, [
|
||||
[
|
||||
'id' => 1,
|
||||
'revision_id' => 2,
|
||||
'revision_user' => $secondary_author->id(),
|
||||
],
|
||||
], static::$columnMap);
|
||||
|
||||
// Build a larger dataset to allow filtering.
|
||||
$block_content2_title = $this->randomString();
|
||||
$block_content2 = BlockContent::create([
|
||||
'info' => $block_content2_title,
|
||||
'type' => 'basic',
|
||||
]);
|
||||
$block_content2->save();
|
||||
$block_content2->setRevisionUser($primary_author);
|
||||
$block_content2->setNewRevision();
|
||||
$block_content2->save();
|
||||
|
||||
$view = Views::getView('test_block_content_revision_user');
|
||||
$this->executeView($view);
|
||||
$this->assertIdenticalResultset($view, [
|
||||
[
|
||||
'id' => 1,
|
||||
'revision_id' => 2,
|
||||
'revision_user' => $secondary_author->id(),
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'revision_id' => 4,
|
||||
'revision_user' => $primary_author->id(),
|
||||
],
|
||||
], static::$columnMap);
|
||||
|
||||
// Test filter by revision_author.
|
||||
$view = Views::getView('test_block_content_revision_user');
|
||||
$view->initHandlers();
|
||||
$view->filter['revision_user']->value = [$secondary_author->id()];
|
||||
$this->executeView($view);
|
||||
$this->assertIdenticalResultset($view, [
|
||||
[
|
||||
'id' => 1,
|
||||
'revision_id' => 2,
|
||||
'revision_user' => $secondary_author->id(),
|
||||
],
|
||||
], static::$columnMap);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue