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:

  1. The hook_group_content_info_alter() changed to hook_group_relation_type_alter()but it still doesn't help and thus I haven't used it at all.
  2. The following service must be changed
    - From: plugin.manager.group_content_enabler (referring to Drupal\group\Plugin\GroupContentEnablerManager)
    - To: group_relation_type.manager (referring to Drupal\group\Plugin\Group\Relation\GroupRelationTypeManager)
  3. 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)
  4. 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)
  5. The AccessUnpublishedGroupPermissions::buildPermissions() must have the following replaced
    - From: 'title' => 'Access unpublished ' . $plugin->getLabel(),
    - To: 'title' => 'Access unpublished ' . $plugin->getPluginDefinition()->get('label') ?? ''
  6. 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)
  7. The following method call must be changed
    - From: GroupContentInterface::getContentPlugin()
    - To: GroupRelationshipInterface::getPlugin()
  8. 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.
  9. 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

Command icon 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

dabbor created an issue. See original summary.

dabbor’s picture

Issue summary: View changes
dabbor’s picture

Adding 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.

dabbor’s picture

Assigned: dabbor » Unassigned
Status: Active » Needs review

The work is ready to be reviewed.

ok4p1’s picture

Hello, 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).

dabbor’s picture

The 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.

dabbor’s picture

StatusFileSize
new18.43 KB

Here'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".

dabbor’s picture

StatusFileSize
new19.4 KB

The 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).

mably made their first commit to this issue’s fork.

mably’s picture

Status: Needs review » Fixed

Pushed 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?

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.