Loading core/modules/node/src/Hook/NodeViewsHooks.php +33 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\user\Entity\Role; use Drupal\views\ViewExecutable; use Drupal\Core\Hook\Attribute\Hook; use Drupal\Core\Hook\Order\Order; /** * Views hook implementations for node. Loading @@ -16,6 +17,38 @@ class NodeViewsHooks { use StringTranslationTrait; /** * Implements hook_views_data_alter(). */ #[Hook('views_data_alter', order: Order::First)] public function viewsDataAlter(array &$data): void { $data['users_field_data']['uid']['relationship'] = [ 'title' => $this->t('Content authored'), 'help' => $this->t('Relate content to the user who created it. This relationship will create one record for each content item created by the user.'), 'id' => 'standard', 'base' => 'node_field_data', 'base field' => 'uid', 'field' => 'uid', 'label' => $this->t('nodes'), ]; $data['users_field_data']['uid_representative'] = [ 'relationship' => [ 'title' => $this->t('Representative node'), 'label' => $this->t('Representative node'), 'help' => $this->t('Obtains a single representative node for each user, according to a chosen sort criterion.'), 'id' => 'groupwise_max', 'relationship field' => 'uid', 'outer field' => 'users_field_data.uid', 'argument table' => 'users_field_data', 'argument field' => 'uid', 'base' => 'node_field_data', 'field' => 'nid', 'relationship' => 'node_field_data:uid', ], ]; } /** * Implements hook_views_analyze(). */ Loading core/modules/user/tests/modules/user_test_views/test_views/views.view.test_groupwise_user.yml→core/modules/node/tests/modules/node_test_views/test_views/views.view.test_groupwise_user.yml +0 −0 File moved. View file core/modules/user/tests/src/Kernel/Views/RelationshipRepresentativeNodeTest.php→core/modules/node/tests/src/Kernel/Views/RelationshipRepresentativeNodeTest.php +4 −4 Original line number Diff line number Diff line Loading @@ -2,7 +2,7 @@ declare(strict_types=1); namespace Drupal\Tests\user\Kernel\Views; namespace Drupal\Tests\node\Kernel\Views; use Drupal\KernelTests\KernelTestBase; use Drupal\Tests\node\Traits\NodeCreationTrait; Loading @@ -16,7 +16,7 @@ /** * Tests the representative node relationship for users. */ #[Group('user')] #[Group('node')] #[RunTestsInSeparateProcesses] class RelationshipRepresentativeNodeTest extends KernelTestBase { Loading @@ -30,9 +30,9 @@ class RelationshipRepresentativeNodeTest extends KernelTestBase { protected static $modules = [ 'filter', 'node', 'node_test_views', 'system', 'user', 'user_test_views', 'views', ]; Loading @@ -50,7 +50,7 @@ public function testRelationship(): void { $this->installEntitySchema('user'); $this->installEntitySchema('node'); $this->installConfig(['filter']); ViewTestData::createTestViews(static::class, ['user_test_views']); ViewTestData::createTestViews(static::class, ['node_test_views']); $users[] = $this->createUser([], NULL, FALSE, ['uid' => 2]); $users[] = $this->createUser([], NULL, FALSE, ['uid' => 1]); Loading core/modules/user/src/UserViewsData.php +0 −25 Original line number Diff line number Diff line Loading @@ -29,15 +29,6 @@ public function getViewsData() { $data['users_field_data']['uid']['filter']['id'] = 'user_name'; $data['users_field_data']['uid']['filter']['title'] = $this->t('Name (autocomplete)'); $data['users_field_data']['uid']['filter']['help'] = $this->t('The user or author name. Uses an autocomplete widget to find a user name, the actual filter uses the resulting user ID.'); $data['users_field_data']['uid']['relationship'] = [ 'title' => $this->t('Content authored'), 'help' => $this->t('Relate content to the user who created it. This relationship will create one record for each content item created by the user.'), 'id' => 'standard', 'base' => 'node_field_data', 'base field' => 'uid', 'field' => 'uid', 'label' => $this->t('nodes'), ]; $data['users_field_data']['uid_raw'] = [ 'help' => $this->t('The raw numeric user ID.'), Loading @@ -48,22 +39,6 @@ public function getViewsData() { ], ]; $data['users_field_data']['uid_representative'] = [ 'relationship' => [ 'title' => $this->t('Representative node'), 'label' => $this->t('Representative node'), 'help' => $this->t('Obtains a single representative node for each user, according to a chosen sort criterion.'), 'id' => 'groupwise_max', 'relationship field' => 'uid', 'outer field' => 'users_field_data.uid', 'argument table' => 'users_field_data', 'argument field' => 'uid', 'base' => 'node_field_data', 'field' => 'nid', 'relationship' => 'node_field_data:uid', ], ]; $data['users']['uid_current'] = [ 'real field' => 'uid', 'title' => $this->t('Current'), Loading Loading
core/modules/node/src/Hook/NodeViewsHooks.php +33 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\user\Entity\Role; use Drupal\views\ViewExecutable; use Drupal\Core\Hook\Attribute\Hook; use Drupal\Core\Hook\Order\Order; /** * Views hook implementations for node. Loading @@ -16,6 +17,38 @@ class NodeViewsHooks { use StringTranslationTrait; /** * Implements hook_views_data_alter(). */ #[Hook('views_data_alter', order: Order::First)] public function viewsDataAlter(array &$data): void { $data['users_field_data']['uid']['relationship'] = [ 'title' => $this->t('Content authored'), 'help' => $this->t('Relate content to the user who created it. This relationship will create one record for each content item created by the user.'), 'id' => 'standard', 'base' => 'node_field_data', 'base field' => 'uid', 'field' => 'uid', 'label' => $this->t('nodes'), ]; $data['users_field_data']['uid_representative'] = [ 'relationship' => [ 'title' => $this->t('Representative node'), 'label' => $this->t('Representative node'), 'help' => $this->t('Obtains a single representative node for each user, according to a chosen sort criterion.'), 'id' => 'groupwise_max', 'relationship field' => 'uid', 'outer field' => 'users_field_data.uid', 'argument table' => 'users_field_data', 'argument field' => 'uid', 'base' => 'node_field_data', 'field' => 'nid', 'relationship' => 'node_field_data:uid', ], ]; } /** * Implements hook_views_analyze(). */ Loading
core/modules/user/tests/modules/user_test_views/test_views/views.view.test_groupwise_user.yml→core/modules/node/tests/modules/node_test_views/test_views/views.view.test_groupwise_user.yml +0 −0 File moved. View file
core/modules/user/tests/src/Kernel/Views/RelationshipRepresentativeNodeTest.php→core/modules/node/tests/src/Kernel/Views/RelationshipRepresentativeNodeTest.php +4 −4 Original line number Diff line number Diff line Loading @@ -2,7 +2,7 @@ declare(strict_types=1); namespace Drupal\Tests\user\Kernel\Views; namespace Drupal\Tests\node\Kernel\Views; use Drupal\KernelTests\KernelTestBase; use Drupal\Tests\node\Traits\NodeCreationTrait; Loading @@ -16,7 +16,7 @@ /** * Tests the representative node relationship for users. */ #[Group('user')] #[Group('node')] #[RunTestsInSeparateProcesses] class RelationshipRepresentativeNodeTest extends KernelTestBase { Loading @@ -30,9 +30,9 @@ class RelationshipRepresentativeNodeTest extends KernelTestBase { protected static $modules = [ 'filter', 'node', 'node_test_views', 'system', 'user', 'user_test_views', 'views', ]; Loading @@ -50,7 +50,7 @@ public function testRelationship(): void { $this->installEntitySchema('user'); $this->installEntitySchema('node'); $this->installConfig(['filter']); ViewTestData::createTestViews(static::class, ['user_test_views']); ViewTestData::createTestViews(static::class, ['node_test_views']); $users[] = $this->createUser([], NULL, FALSE, ['uid' => 2]); $users[] = $this->createUser([], NULL, FALSE, ['uid' => 1]); Loading
core/modules/user/src/UserViewsData.php +0 −25 Original line number Diff line number Diff line Loading @@ -29,15 +29,6 @@ public function getViewsData() { $data['users_field_data']['uid']['filter']['id'] = 'user_name'; $data['users_field_data']['uid']['filter']['title'] = $this->t('Name (autocomplete)'); $data['users_field_data']['uid']['filter']['help'] = $this->t('The user or author name. Uses an autocomplete widget to find a user name, the actual filter uses the resulting user ID.'); $data['users_field_data']['uid']['relationship'] = [ 'title' => $this->t('Content authored'), 'help' => $this->t('Relate content to the user who created it. This relationship will create one record for each content item created by the user.'), 'id' => 'standard', 'base' => 'node_field_data', 'base field' => 'uid', 'field' => 'uid', 'label' => $this->t('nodes'), ]; $data['users_field_data']['uid_raw'] = [ 'help' => $this->t('The raw numeric user ID.'), Loading @@ -48,22 +39,6 @@ public function getViewsData() { ], ]; $data['users_field_data']['uid_representative'] = [ 'relationship' => [ 'title' => $this->t('Representative node'), 'label' => $this->t('Representative node'), 'help' => $this->t('Obtains a single representative node for each user, according to a chosen sort criterion.'), 'id' => 'groupwise_max', 'relationship field' => 'uid', 'outer field' => 'users_field_data.uid', 'argument table' => 'users_field_data', 'argument field' => 'uid', 'base' => 'node_field_data', 'field' => 'nid', 'relationship' => 'node_field_data:uid', ], ]; $data['users']['uid_current'] = [ 'real field' => 'uid', 'title' => $this->t('Current'), Loading