Loading core/modules/content_moderation/src/Plugin/views/filter/ModerationStateFilter.php +1 −1 Original line number Diff line number Diff line Loading @@ -137,7 +137,7 @@ protected function opSimple() { // If we have a list of moderated bundles, restrict the query to show only // entities in those bundles. if ($moderated_bundles) { $entity_base_table_alias = $this->table; $entity_base_table_alias = $this->relationship ?: $this->table; // The bundle field of an entity type is not revisionable so we need to // join the base table. Loading core/modules/content_moderation/tests/modules/content_moderation_test_views/config/install/views.view.test_content_moderation_filter_via_relationship.yml 0 → 100644 +348 −0 Original line number Diff line number Diff line langcode: en status: true dependencies: module: - content_moderation - node - user id: test_content_moderation_filter_via_relationship label: test_content_moderation_filter_via_relationship module: views description: '' tag: '' base_table: users_field_data base_field: uid display: default: display_plugin: default id: default display_title: Master position: 0 display_options: access: type: perm options: perm: 'access user profiles' 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 row: type: fields fields: name: id: name table: users_field_data field: name 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: false ellipsis: false 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: user_name settings: link_to_entity: 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: user entity_field: name plugin_id: field title: id: title table: node_field_data field: title relationship: uid 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: string settings: link_to_entity: 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: node entity_field: title plugin_id: field moderation_state: id: moderation_state table: node_field_data field: moderation_state relationship: uid 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: content_moderation_state settings: { } 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: node plugin_id: moderation_state_field filters: moderation_state: id: moderation_state table: node_field_data field: moderation_state relationship: uid group_type: group admin_label: '' operator: in value: { } group: 1 exposed: true expose: operator_id: moderation_state_op label: 'Moderation state' description: '' use_operator: false operator: moderation_state_op identifier: moderation_state 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: node plugin_id: moderation_state_filter sorts: vid: id: vid table: node_field_data field: vid relationship: uid group_type: group admin_label: '' order: ASC exposed: false expose: label: '' entity_type: node entity_field: vid plugin_id: standard title: test_content_moderation_filter_via_relationship header: { } footer: { } empty: { } relationships: uid: id: uid table: users_field_data field: uid relationship: none group_type: group admin_label: nodes required: true entity_type: user entity_field: uid plugin_id: standard arguments: { } display_extenders: { } cache_metadata: max-age: -1 contexts: - 'languages:language_content' - 'languages:language_interface' - url - user.permissions tags: - 'config:workflow_list' page_1: display_plugin: page id: page_1 display_title: Page position: 1 display_options: display_extenders: { } path: test-content-moderation-filter-relationship cache_metadata: max-age: -1 contexts: - 'languages:language_content' - 'languages:language_interface' - url - user.permissions tags: - 'config:workflow_list' core/modules/content_moderation/tests/src/Kernel/ViewsModerationStateFilterTest.php +48 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait; use Drupal\Tests\user\Traits\UserCreationTrait; use Drupal\Tests\views\Kernel\ViewsKernelTestBase; use Drupal\views\Views; use Drupal\workflows\Entity\Workflow; Loading @@ -21,6 +22,7 @@ class ViewsModerationStateFilterTest extends ViewsKernelTestBase { use ContentModerationTestTrait; use UserCreationTrait; /** * {@inheritdoc} Loading Loading @@ -183,6 +185,52 @@ public function testNonTranslatableEntityType() { $this->assertIdenticalResultset($view, [['id' => $test_entity->id()]], ['id' => 'id']); } /** * Tests the moderation state filter on an entity added via a relationship. */ public function testModerationStateFilterOnJoinedEntity() { $workflow = Workflow::load('editorial'); $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'example'); $workflow->save(); // Create some sample content that will satisfy a view of users with a // relationship to an item of content. $user = $this->createUser([], 'Test user'); $node = Node::create([ 'type' => 'example', 'title' => 'Test node', 'moderation_state' => 'published', 'uid' => $user->id(), ]); $node->save(); // When filtering by published nodes, the sample content will appear. $view = Views::getView('test_content_moderation_filter_via_relationship'); $view->setExposedInput([ 'moderation_state' => 'editorial-published', ]); $view->execute(); $this->assertIdenticalResultset($view, [ [ 'name' => 'Test user', 'title' => 'Test node', 'moderation_state' => 'published', ], ], [ 'name' => 'name', 'title' => 'title', 'moderation_state' => 'moderation_state', ]); // Filtering by the draft state will filter out the sample content. $view = Views::getView('test_content_moderation_filter_via_relationship'); $view->setExposedInput([ 'moderation_state' => 'editorial-draft', ]); $view->execute(); $this->assertIdenticalResultset($view, [], ['name' => 'name']); } /** * Tests the list of states in the filter plugin. */ Loading Loading
core/modules/content_moderation/src/Plugin/views/filter/ModerationStateFilter.php +1 −1 Original line number Diff line number Diff line Loading @@ -137,7 +137,7 @@ protected function opSimple() { // If we have a list of moderated bundles, restrict the query to show only // entities in those bundles. if ($moderated_bundles) { $entity_base_table_alias = $this->table; $entity_base_table_alias = $this->relationship ?: $this->table; // The bundle field of an entity type is not revisionable so we need to // join the base table. Loading
core/modules/content_moderation/tests/modules/content_moderation_test_views/config/install/views.view.test_content_moderation_filter_via_relationship.yml 0 → 100644 +348 −0 Original line number Diff line number Diff line langcode: en status: true dependencies: module: - content_moderation - node - user id: test_content_moderation_filter_via_relationship label: test_content_moderation_filter_via_relationship module: views description: '' tag: '' base_table: users_field_data base_field: uid display: default: display_plugin: default id: default display_title: Master position: 0 display_options: access: type: perm options: perm: 'access user profiles' 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 row: type: fields fields: name: id: name table: users_field_data field: name 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: false ellipsis: false 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: user_name settings: link_to_entity: 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: user entity_field: name plugin_id: field title: id: title table: node_field_data field: title relationship: uid 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: string settings: link_to_entity: 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: node entity_field: title plugin_id: field moderation_state: id: moderation_state table: node_field_data field: moderation_state relationship: uid 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: content_moderation_state settings: { } 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: node plugin_id: moderation_state_field filters: moderation_state: id: moderation_state table: node_field_data field: moderation_state relationship: uid group_type: group admin_label: '' operator: in value: { } group: 1 exposed: true expose: operator_id: moderation_state_op label: 'Moderation state' description: '' use_operator: false operator: moderation_state_op identifier: moderation_state 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: node plugin_id: moderation_state_filter sorts: vid: id: vid table: node_field_data field: vid relationship: uid group_type: group admin_label: '' order: ASC exposed: false expose: label: '' entity_type: node entity_field: vid plugin_id: standard title: test_content_moderation_filter_via_relationship header: { } footer: { } empty: { } relationships: uid: id: uid table: users_field_data field: uid relationship: none group_type: group admin_label: nodes required: true entity_type: user entity_field: uid plugin_id: standard arguments: { } display_extenders: { } cache_metadata: max-age: -1 contexts: - 'languages:language_content' - 'languages:language_interface' - url - user.permissions tags: - 'config:workflow_list' page_1: display_plugin: page id: page_1 display_title: Page position: 1 display_options: display_extenders: { } path: test-content-moderation-filter-relationship cache_metadata: max-age: -1 contexts: - 'languages:language_content' - 'languages:language_interface' - url - user.permissions tags: - 'config:workflow_list'
core/modules/content_moderation/tests/src/Kernel/ViewsModerationStateFilterTest.php +48 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait; use Drupal\Tests\user\Traits\UserCreationTrait; use Drupal\Tests\views\Kernel\ViewsKernelTestBase; use Drupal\views\Views; use Drupal\workflows\Entity\Workflow; Loading @@ -21,6 +22,7 @@ class ViewsModerationStateFilterTest extends ViewsKernelTestBase { use ContentModerationTestTrait; use UserCreationTrait; /** * {@inheritdoc} Loading Loading @@ -183,6 +185,52 @@ public function testNonTranslatableEntityType() { $this->assertIdenticalResultset($view, [['id' => $test_entity->id()]], ['id' => 'id']); } /** * Tests the moderation state filter on an entity added via a relationship. */ public function testModerationStateFilterOnJoinedEntity() { $workflow = Workflow::load('editorial'); $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'example'); $workflow->save(); // Create some sample content that will satisfy a view of users with a // relationship to an item of content. $user = $this->createUser([], 'Test user'); $node = Node::create([ 'type' => 'example', 'title' => 'Test node', 'moderation_state' => 'published', 'uid' => $user->id(), ]); $node->save(); // When filtering by published nodes, the sample content will appear. $view = Views::getView('test_content_moderation_filter_via_relationship'); $view->setExposedInput([ 'moderation_state' => 'editorial-published', ]); $view->execute(); $this->assertIdenticalResultset($view, [ [ 'name' => 'Test user', 'title' => 'Test node', 'moderation_state' => 'published', ], ], [ 'name' => 'name', 'title' => 'title', 'moderation_state' => 'moderation_state', ]); // Filtering by the draft state will filter out the sample content. $view = Views::getView('test_content_moderation_filter_via_relationship'); $view->setExposedInput([ 'moderation_state' => 'editorial-draft', ]); $view->execute(); $this->assertIdenticalResultset($view, [], ['name' => 'name']); } /** * Tests the list of states in the filter plugin. */ Loading