Problem/Motivation
There is an issue (feature request): "Support Group content" https://www.drupal.org/project/access_unpublished/issues/3280964 that works for Group 1.x.
This issue focused on support of Group 2.x which has significantly modified access control.
The way Groups handles access control doesn't work natively with Access Unpublished for Group managed content.
Steps to reproduce
Quoting from https://www.drupal.org/project/access_unpublished/issues/3280964
Install Group, Group Node, and Access Unpublished. Setup a Group Type, and add allow content type to it. Create group content of that type. Create a link with Access Unpublished - it will result in Access Denied.
Proposed resolution
Modifying the work implemented in https://www.drupal.org/project/access_unpublished/issues/3280964 (access_unpublished_group sub-module) to get it compatible with Group 2.x following the https://www.drupal.org/docs/extending-drupal/contributed-modules/contrib... and checking the differences in Group 1.x and Group 2.x codebase I found out that following had to be done:
- The
hook_group_content_info_alter()changed tohook_group_relation_type_alter()but it still doesn't help and thus I haven't used it at all. - The following service must be changed
- From:plugin.manager.group_content_enabler(referring toDrupal\group\Plugin\GroupContentEnablerManager)
- To:group_relation_type.manager(referring toDrupal\group\Plugin\Group\Relation\GroupRelationTypeManager) - The interface of the plugin manager service above must be changed
- From:GroupContentEnablerManagerInterface(name-spaced:Drupal\group\Plugin\GroupContentEnablerManagerInterface)
- To:GroupRelationTypeManagerInterface(name-spaced:Drupal\group\Plugin\Group\Relation\GroupRelationTypeManagerInterface) - The interface of the plugin must be changed
- From:GroupContentEnablerInterface(name-spaced:Drupal\Group\Plugin\GroupContentEnablerInterface)
- To:GroupRelationInterface(name-spaced:Drupal\group\Plugin\Group\Relation\GroupRelationInterface) - The
AccessUnpublishedGroupPermissions::buildPermissions()must have the following replaced
- From:'title' => 'Access unpublished ' . $plugin->getLabel(),
- To:'title' => 'Access unpublished ' . $plugin->getPluginDefinition()->get('label') ?? '' - The interface for group content entity storage classes must be changed to interface for relationship entity storage classes
- From:GroupContentStorageInterface(name-spaced:Drupal\group\Entity\Storage\GroupContentStorageInterface)
- To:GroupRelationshipStorageInterface(name-spaced:Drupal\group\Entity\Storage\GroupRelationshipStorageInterface) - The following method call must be changed
- From:GroupContentInterface::getContentPlugin()
- To:GroupRelationshipInterface::getPlugin() - Implement ServiceProvider similarly as Group 2.x contrib does in its
GroupServiceProvider(Drupal\group\GroupServiceProvider) to decorate the original access control services provided by Group 2.x or another module. - The new decorated services are overriding the
AccessControlInterface::entityAccess()
Remaining tasks
Code review / Test coverage (happy to get a help).
User interface changes
Quoting from https://www.drupal.org/project/access_unpublished/issues/3280964
The proof of concept adds group level permissions so access_unpublished can be allowed per group type and group role.
API changes
N/A
Data model changes
N/A
Issue fork access_unpublished-3405874
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
dabbor commentedComment #4
dabbor commentedAdding a patch of the current MR to be linked in composer (interdiff to work implemented in https://www.drupal.org/project/access_unpublished/issues/3280964.
Comment #5
dabbor commentedThe work is ready to be reviewed.
Comment #6
ok4p1 commentedHello, are you planning to make this work with groups 3.x? I tried the patch but got the following error, thanks.
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "group_content" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 139 of core/lib/Drupal/Core/Entity/EntityTypeManager.php).
Comment #7
dabbor commentedThe MR was updated with one new commit https://git.drupalcode.org/project/access_unpublished/-/merge_requests/1... to support changes implemented in the latest Group 2.x version (
2.3.1).Adding a patch of the current MR to be linked in composer (interdiff included as well).
Regarding comment #6, I'm not planning to do it myself (at least not now), but you can follow the instructions like:
a.) The same way as I made migration of https://www.drupal.org/project/access_unpublished/issues/3280964 by following instructions in: https://www.drupal.org/docs/extending-drupal/contributed-modules/contrib...
b.) You should be able to the the same as I did, creating a new ticket with name like Support Group 3.x content and migrate my work following instructions in https://www.drupal.org/docs/extending-drupal/contributed-modules/contrib... which should be much less work.
Comment #8
dabbor commentedHere's the promissed patch that should have been added in my previous comment of the current MR to be linked in composer.
P.S. Either I forgot to click "Upload" or the file got lost when I clicked "Preview".
Comment #9
dabbor commentedThe MR was updated with one new commit https://git.drupalcode.org/project/access_unpublished/-/merge_requests/1... to be compatible with Drupal 11.
Adding a patch of the current MR to be linked in composer (using the https://git.drupalcode.org/project/access_unpublished/-/merge_requests/1... URL to generate the patch).
Comment #11
mably commentedPushed to the 2.x branch of the newly created contrib module:
https://www.drupal.org/project/access_unpublished_group
@dabbor are you interested in becoming a maintainer of this new module?