diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 449e6bd0862b728b7f5f67053764333846f57246..f08c7862913bc678c5f9a79b16fd37ab023c01ca 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -64,7 +64,7 @@ group_integration: _PHPUNIT_TESTGROUPS: group_integration parallel: matrix: - - GROUP_VERSION: [ '^1', '^2' ] + - GROUP_VERSION: [ '^2', '^3'] ################################################################################### # diff --git a/composer.json b/composer.json index 62d97b0de636e82d0f40f9fa96f059f63cfe1964..ecf8ae5dc118e9f1c99437c020db935d2a7a02fa 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,6 @@ }, "require-dev": { "drupal/paragraphs": "1.x-dev", - "drupal/group": "^1 || ^2 || ^3" + "drupal/group": "^2 || ^3" } } diff --git a/quick_node_clone.module b/quick_node_clone.module index 0638730f04e513c9bf5087215adaeaeb7ae8955b..b634e987f7b6f2f7cbdb4e9421a8eb97ae4d6b7c 100644 --- a/quick_node_clone.module +++ b/quick_node_clone.module @@ -12,7 +12,6 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; -use Drupal\group\Entity\GroupContent; use Drupal\group\Entity\GroupRelationship; use Drupal\group\Plugin\Group\Relation\GroupRelationTypeManagerInterface; @@ -116,30 +115,18 @@ function _quick_node_clone_has_clone_permission(ContentEntityInterface $node) { $bundle = $node->bundle(); if ($current_user->hasPermission("clone $bundle content")) { if (\Drupal::moduleHandler()->moduleExists('gnode')) { - // Check that user has permission to create a relationship. - // Support for group module version 1.x. - if (class_exists(GroupContent::class)) { - $group_relationships = GroupContent::loadByEntity($node); - foreach ($group_relationships as $group_relationship) { - $access = $group_relationship->getContentPlugin()->createEntityAccess($group_relationship->getGroup(), $current_user); - if ($access->isAllowed()) { - return TRUE; - } - } - } - // Support for group module version 2.x and 3.x. - else { - $group_relationships = GroupRelationship::loadByEntity($node); - $relation_type_manager = \Drupal::service('group_relation_type.manager'); - assert($relation_type_manager instanceof GroupRelationTypeManagerInterface); - foreach ($group_relationships as $group_relationship) { - $access_handler = $relation_type_manager->getAccessControlHandler($group_relationship->getPluginId()); - $access = $access_handler->entityCreateAccess($group_relationship->getGroup(), $current_user); - if ($access) { - return TRUE; - } + + $group_relationships = GroupRelationship::loadByEntity($node); + $relation_type_manager = \Drupal::service('group_relation_type.manager'); + assert($relation_type_manager instanceof GroupRelationTypeManagerInterface); + foreach ($group_relationships as $group_relationship) { + $access_handler = $relation_type_manager->getAccessControlHandler($group_relationship->getPluginId()); + $access = $access_handler->entityCreateAccess($group_relationship->getGroup(), $current_user); + if ($access) { + return TRUE; } } + } // Only check global access if we there is no group module enabled, or diff --git a/tests/src/Functional/QuickNodeCloneGroupIntegrationTest.php b/tests/src/Functional/QuickNodeCloneGroupIntegrationTest.php index 19c0dc88d0b2592a76799645a4f396b4d81b6bdd..4df23659b5f056ef37d11e19a6845fcfad001caf 100644 --- a/tests/src/Functional/QuickNodeCloneGroupIntegrationTest.php +++ b/tests/src/Functional/QuickNodeCloneGroupIntegrationTest.php @@ -5,11 +5,9 @@ namespace Drupal\Tests\quick_node_clone\Functional; use Drupal\Tests\BrowserTestBase; use Drupal\Tests\node\Traits\NodeCreationTrait; use Drupal\group\Entity\Group; -use Drupal\group\Entity\GroupContent; use Drupal\group\Entity\GroupRelationship; use Drupal\group\Entity\GroupRole; use Drupal\group\Entity\GroupType; -use Drupal\group\Entity\Storage\GroupContentTypeStorageInterface; use Drupal\group\Entity\Storage\GroupRelationshipTypeStorageInterface; use Drupal\group\PermissionScopeInterface; @@ -59,73 +57,6 @@ class QuickNodeCloneGroupIntegrationTest extends BrowserTestBase { * Test node cloning. */ public function testNodeClone() { - if (class_exists(GroupContent::class)) { - $this->checkGroupContent(); - } - else { - $this->checkGroupRelations(); - } - } - - /** - * Test groups v1. - */ - public function checkGroupContent() { - // Prepare a group type. - $group_type = GroupType::create([ - 'id' => $this->randomMachineName(), - 'label' => $this->randomString(), - 'creator_wizard' => FALSE, - ]); - $group_type->save(); - $node_type = 'page'; - $gnode_plugin_id = 'group_node:' . $node_type; - $content_type_storage = $this->entityTypeManager->getStorage('group_content_type'); - /* @phpstan-ignore-next-line */ - assert($content_type_storage instanceof GroupContentTypeStorageInterface); - $content_type_storage->save($content_type_storage->createFromPlugin($group_type, $gnode_plugin_id)); - - // Create a node and add it to a group. - $node = $this->createNode([ - 'type' => $node_type, - 'title' => $this->randomString(200), - ]); - $group = Group::create([ - 'type' => $group_type->id(), - 'label' => $this->randomString(), - ]); - $group->save(); - $group->addContent($node, $gnode_plugin_id); - - // Create a user with the required permissions. - $group_role = GroupRole::create([ - 'group_type' => $group_type->id(), - 'id' => $this->randomMachineName(), - 'label' => $this->randomString(), - 'permissions' => ['administer group'], - ]); - $group_role->save(); - $user = $this->drupalCreateUser(["clone $node_type content"]); - $group->addMember($user, ['group_roles' => [$group_role->id()]]); - - // Clone the node and check that it is added to the group. - $this->drupalLogin($user); - $this->drupalGet("clone/{$node->id()}/quick_clone"); - $cloned_node_title = $this->randomMachineName(200); - $edit = [ - 'title[0][value]' => $cloned_node_title, - ]; - $this->submitForm($edit, 'Save'); - $cloned_node = $this->getNodeByTitle($cloned_node_title); - /* @phpstan-ignore-next-line */ - $cloned_relation = GroupContent::loadByEntity($cloned_node); - $this->assertCount(1, $cloned_relation); - } - - /** - * Test groups v2 and higher. - */ - protected function checkGroupRelations() { // Prepare a group type. $group_type = GroupType::create([ 'id' => $this->randomMachineName(), @@ -136,8 +67,8 @@ class QuickNodeCloneGroupIntegrationTest extends BrowserTestBase { // Determine the relation type entity ID // for the installed version of the group module (v2 or v3). $relation_type_id = $this->entityTypeManager->getDefinition('group_content_type', FALSE) - ? 'group_content_type' - : 'group_relationship_type'; + ? 'group_content_type' + : 'group_relationship_type'; $relation_type_storage = $this->entityTypeManager->getStorage($relation_type_id); assert($relation_type_storage instanceof GroupRelationshipTypeStorageInterface); $node_type = 'page';