We are using this module with Workbench Moderation to support clients requirement to be able to quickly review unpublished/Draft content before they get published.
This module seems to work fine initially when new content gets created and saved as a draft. However, if an existing node is edited and saved as a draft. Users are redirected to the published version of the node, not the latest revision draft page.

Comments

jchand created an issue. See original summary.

jchand’s picture

Version: 8.x-1.0-alpha1 » 8.x-1.x-dev
findleys’s picture

Project: View Unpublished » Access unpublished
Category: Support request » Bug report
chr.fritsch’s picture

Status: Active » Postponed (maintainer needs more info)

I am not sure if the issue belongs to the access_unpublish module. Can someone please clarify that?

vivify’s picture

1. Create and save article node without publishing.
2. Generate a link to the unpublished node.
3. Visit page with link and everything is fine.
4. Publish the article node.
5. Go back and edit that same article node and create a draft revision.
6. Visit link to the node again. Link shows previous published revision and not new draft revision.

findleys’s picture

Status: Postponed (maintainer needs more info) » Active
chr.fritsch’s picture

Status: Active » Needs review
StatusFileSize
new6.21 KB

Ah ok, now i get it.

So here is a patch to support cores content_moderation module.

chr.fritsch’s picture

Title: View Unpublished not working with the latest revision » Access unpublished not working together with content moderation
chr.fritsch’s picture

StatusFileSize
new5.5 KB

Re-roll

vegantriathlete’s picture

I must say that I'm very happy to see work on this! It will be a great new feature to add to the module. I'll have a look at the patch and see if I've got anything to contribute.

vegantriathlete’s picture

It appears to me that your patch is designed to work with Drupal's content moderation as opposed to Workbench Moderation. I can understand that it's easier to do that. However, this issue specifically asks about getting this module to work with Workbench Moderation.

vegantriathlete’s picture

I know that, per the project page for Workbench Moderation

Since Drupal 8.2.x this module is in core as "Content Moderation".

Unfortunately, I don't believe there is any upgrade path from Workbench Moderation to Content Moderation at this point.

vegantriathlete’s picture

So the question is, what is the best path forward? It's great to get this module to work with Content Moderation.

  • What do we do about Workbench Moderation?
  • Is there a way that we can have logic that is conditional on Workbench Moderation being installed?
  • Would we have to make any changes to the Workbench Moderation module?
vegantriathlete’s picture

Note: As of 8.5.x Content Moderation is no longer marked as experimental.

chr.fritsch’s picture

As you noted, workbench_moderation was replaced by content_moderation and it's stable since D 8.5. I would like to avoid offering support for workbench_moderation since it would make the code much more complex.

FYI: The upgrade path workbench_moderation -> content_moderation can be found here: https://www.drupal.org/project/wbm2cm

vegantriathlete’s picture

Perfect! Thanks for the link to the migration path. I'm comfortable with the call to not provide support for Workbench Moderation.

chr.fritsch’s picture

StatusFileSize
new8.09 KB

Added some tests

alexpott’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new8.29 KB
new11.28 KB
  1. +++ b/src/AccessUnpublishedServiceProvider.php
    @@ -0,0 +1,28 @@
    +    if ($container->hasDefinition('access_check.latest_revision')) {
    +      $definition = $container->getDefinition('access_check.latest_revision');
    +      $definition->setClass('Drupal\access_unpublished\Access\LatestRevisionCheck');
    +    }
    

    Doing this doesn't play nice with other overrides. Ideally we'd inform everyone this is a really bad way to change functionality. We should decorate the service instead. That way if something else decorates there is a chance that we all play nice together.

    I tried to implement the change as just another access check but since \Drupal\Core\Access\AccessManager::check() uses andIf() this is not possible. This kind of surprises me but anyhow patch attached does the decoration.

  2. +++ b/tests/src/Functional/ContentModerationAccessTest.php
    @@ -0,0 +1,108 @@
    +    $expiredToken = AccessToken::create([
    +      'entity_type' => 'node',
    +      'entity_id' => $this->entity->id(),
    +      'value' => 'iAmExpired',
    +      'expire' => REQUEST_TIME - 100,
    +    ]);
    +    $expiredToken->save();
    

    Not used - I guess a c&p. Removed.

  3. +++ b/tests/src/Functional/ContentModerationAccessTest.php
    @@ -0,0 +1,108 @@
    +      'expire' => REQUEST_TIME + 100,
    

    Added more time here because it wasn't long enough for a decent debug session.

  4. This looks ready to me now.

  • chr.fritsch committed b93b6b8 on 8.x-1.x authored by alexpott
    Issue #2861940 by chr.fritsch, alexpott: Access unpublished not working...
chr.fritsch’s picture

Status: Reviewed & tested by the community » Fixed

I tested your patch. Everything worked nicely and your solution is much more future proof.

Thank you.

Committed and pushed.

Status: Fixed » Closed (fixed)

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