diff --git a/core/modules/node/src/Plugin/views/argument/UidRevision.php b/core/modules/node/src/Plugin/views/argument/UidRevision.php index 9e2fb810c2cdc5a9d827716dadc639e488e34365..0f989a7a332651560f42bdd7f8b5084f0c0a0985 100644 --- a/core/modules/node/src/Plugin/views/argument/UidRevision.php +++ b/core/modules/node/src/Plugin/views/argument/UidRevision.php @@ -15,7 +15,7 @@ class UidRevision extends Uid { public function query($group_by = FALSE) { $this->ensureMyTable(); $placeholder = $this->placeholder(); - $this->query->addWhereExpression(0, "$this->tableAlias.revision_uid = $placeholder OR ((SELECT COUNT(DISTINCT vid) FROM {node_revision} nr WHERE nfr.revision_uid = $placeholder AND nr.nid = $this->tableAlias.nid) > 0)", [$placeholder => $this->argument]); + $this->query->addWhereExpression(0, "$this->tableAlias.uid = $placeholder OR ((SELECT COUNT(DISTINCT vid) FROM {node_revision} nr WHERE nr.revision_uid = $placeholder AND nr.nid = $this->tableAlias.nid) > 0)", [$placeholder => $this->argument]); } } diff --git a/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_argument_node_uid_revision.yml b/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_argument_node_uid_revision.yml new file mode 100644 index 0000000000000000000000000000000000000000..00ee678fc5a40937d1439c5cf06d54550efbb211 --- /dev/null +++ b/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_argument_node_uid_revision.yml @@ -0,0 +1,106 @@ +langcode: en +status: true +dependencies: + module: + - node + - user +id: test_argument_node_uid_revision +label: test_argument_node_uid_revision +module: views +description: '' +tag: default +base_table: node_field_data +base_field: nid +core: 8.0-dev +display: + default: + display_options: + access: + type: perm + cache: + type: tag + exposed_form: + type: basic + fields: + nid: + id: nid + table: node_field_data + field: nid + plugin_id: field + entity_type: node + entity_field: nid + filter_groups: + groups: + 1: AND + operator: AND + filters: { } + sorts: + nid: + id: nid + table: node_field_data + field: nid + order: ASC + plugin_id: standard + relationship: none + entity_type: node + entity_field: nid + pager: + type: full + query: + type: views_query + style: + type: default + row: + type: fields + display_extenders: { } + arguments: + uid_revision: + id: uid_revision + table: node_field_data + field: uid_revision + relationship: none + group_type: group + admin_label: '' + default_action: empty + exception: + value: all + title_enable: false + title: All + title_enable: false + title: '' + default_argument_type: fixed + default_argument_options: + argument: '' + default_argument_skip_url: false + summary_options: + base_path: '' + count: true + items_per_page: 25 + override: false + summary: + sort_order: asc + number_of_records: 0 + format: default_summary + specify_validation: false + validate: + type: none + fail: 'not found' + validate_options: { } + break_phrase: false + not: false + entity_type: node + plugin_id: node_uid_revision + display_plugin: default + display_title: Master + id: default + position: 0 + 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/node/tests/src/Kernel/Views/ArgumentUidRevisionTest.php b/core/modules/node/tests/src/Kernel/Views/ArgumentUidRevisionTest.php new file mode 100644 index 0000000000000000000000000000000000000000..b216f40fb26a8f7a58e0929a29b292b59b33b390 --- /dev/null +++ b/core/modules/node/tests/src/Kernel/Views/ArgumentUidRevisionTest.php @@ -0,0 +1,93 @@ +<?php + +namespace Drupal\Tests\node\Kernel\Views; + +use Drupal\node\Entity\Node; +use Drupal\simpletest\UserCreationTrait; +use Drupal\Tests\views\Kernel\ViewsKernelTestBase; +use Drupal\views\Tests\ViewTestData; +use Drupal\views\Views; + +/** + * Tests the argument_node_uid_revision handler. + * + * @group node + */ +class ArgumentUidRevisionTest extends ViewsKernelTestBase { + use UserCreationTrait; + + /** + * {@inheritdoc} + */ + public static $modules = ['node', 'field', 'text', 'user', 'node_test_views']; + + /** + * {@inheritdoc} + */ + public static $testViews = ['test_argument_node_uid_revision']; + + /** + * {@inheritdoc} + */ + protected function setUp($import_test_views = TRUE) { + parent::setUp($import_test_views); + + $this->installEntitySchema('node'); + $this->installSchema('node', ['node_access']); + $this->installEntitySchema('user'); + $this->installConfig(['node', 'field']); + + ViewTestData::createTestViews(get_class($this), ['node_test_views']); + } + + /** + * Tests the node_uid_revision argument. + */ + public function testArgument() { + $expected_result = []; + + $author = $this->createUser(); + $no_author = $this->createUser(); + + // Create one node, with the author as the node author. + $node1 = Node::create([ + 'type' => 'default', + 'title' => $this->randomMachineName(), + ]); + $node1->setOwner($author); + $node1->save(); + $expected_result[] = ['nid' => $node1->id()]; + + // Create one node of which an additional revision author will be the + // author. + $node2 = Node::create([ + 'type' => 'default', + 'title' => $this->randomMachineName(), + ]); + $node2->setRevisionAuthorId($no_author->id()); + $node2->save(); + $expected_result[] = ['nid' => $node2->id()]; + + // Force to add a new revision. + $node2->setNewRevision(TRUE); + $node2->setRevisionAuthorId($author->id()); + $node2->save(); + + // Create one node on which the author has neither authorship of revisions + // or the main node. + $node3 = Node::create([ + 'type' => 'default', + 'title' => $this->randomMachineName(), + ]); + $node3->setOwner($no_author); + $node3->save(); + + $view = Views::getView('test_argument_node_uid_revision'); + $view->initHandlers(); + $view->setArguments(['uid_revision' => $author->id()]); + + $this->executeView($view); + $this->assertIdenticalResultset($view, $expected_result, ['nid' => 'nid']); + } + +}