Problem/Motivation

On entities with the moderation form displayed when viewing the entity the form does not display if entity is in initial draft.

Note this issue came from workbench_moderation where it is being fixed in #2733127: Can't moderate new content - moderation controls don't appear on new nodes.

Proposed resolution

Change the check in EntityOperations::entityView to hide the form if the entity is the live revision, rather than if it is the default revision.

Remaining tasks

Review code

User interface changes

None

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fenstrat created an issue. See original summary.

fenstrat’s picture

Failing tests.

fenstrat’s picture

Sam152’s picture

  1. +++ b/core/modules/content_moderation/src/EntityOperations.php
    @@ -234,8 +234,7 @@ public function entityView(array &$build, EntityInterface $entity, EntityViewDis
    -    if ($entity->isDefaultRevision()) {
    +    if ($this->moderationInfo->isLiveRevision($entity)) {
    
    A "live" entity revision is one whose latest revision is also the default, and whose moderation state, if any, is a published state.

    The docblock on this method would indicate this change makes total sense. Nice.

  2. +++ b/core/modules/content_moderation/src/Tests/ModerationFormTest.php
    @@ -43,6 +43,12 @@ public function testModerationForm() {
    +    // The published view should have a moderation form, because it is not the
    +    // live revision.
    

    Maybe the comment shouldn't use "published view" because the case we are fixing is specifically a draft, unpublished revision. Maybe "canonical view" is better given the variable name.

  3. +++ b/core/modules/content_moderation/src/Tests/ModerationFormTest.php
    @@ -43,6 +43,12 @@ public function testModerationForm() {
    +    $this->assertText('Status', 'The node view page has a moderation form.');
    
    @@ -53,6 +59,12 @@ public function testModerationForm() {
    +    $this->assertText('Status', 'The node view page has a moderation form.');
    

    Maybe ::assertField would be a better assertion for if the moderation form exists or not. "Status" feels like it could drift into false positive territory.

The last submitted patch, 2: 2864938-2-show-moderate-form-failing-test.patch, failed testing.

fenstrat’s picture

Status: Needs review » Needs work

@Sam152 cheers for the review!

  1. Excellent
  2. Good point, will change
  3. Yeah that checking of 'Status' runs all through that test, will change them all to assertField

I should get to this later today.

fenstrat’s picture

  1. As per #42. changes comments "default" > "live".
  2. As per #4 3. swapped assertText('Draft'... for assertField('edit-new-state' to avoid false positives.

The last submitted patch, 7: 2864938-7-show-moderate-form.patch, failed testing.

The last submitted patch, 7: 2864938-7-show-moderate-form.patch, failed testing.

The last submitted patch, 7: 2864938-7-show-moderate-form.patch, failed testing.

The last submitted patch, 7: 2864938-7-show-moderate-form.patch, failed testing.

Sam152’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
35.66 KB
53.59 KB
46.55 KB

Manual testing looks good. I don't think this needs a usability review as it's a bug fix that makes things more consistent. Amended workflow looks like:

Brand new article in a draft state:

After it has been published:

Once it's back in a draft state:

I like it, looks good.

timmillwood’s picture

dawehner’s picture

At least from a user point of view being able to see it on draft only content totally makes sense.

Sam152’s picture

Issue tags: +Workflow Initiative
timmillwood’s picture

Just comparing the patch here and the patch in #2815921: Allow to use the EntityModerationForm on non forward revision pages, I think this is a better implementation.

Sam152’s picture

Having also reviewed both of these patches again, I think they are functionally exactly the same. The reason being, for any revision with a published state we also force that revision to be the default revision.

Hence I believe:

$this->moderationInfo->getWorkflowForEntity($entity)->getState($entity->moderation_state->value)->isPublishedState()

will have the exact same outcomes as:

$this->moderationInfo->isLiveRevision($entity)
jhedstrom’s picture

@timmillwood pointed me here from #2870484: No way to moderate content that hasn't been published already.

I tested this approach, and while it addresses the issue of new content, it doesn't allow for moderating content out of a published state (which might only apply to advanced workflows).

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Needs a reroll.

timmillwood’s picture

Issue tags: +Needs reroll
timmillwood’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll
FileSize
3.68 KB

Here's the reroll.

  • catch committed e88cca5 on 8.4.x
    Issue #2864938 by fenstrat, timmillwood, Sam152: Content moderation form...

  • catch committed 3c38821 on 8.3.x
    Issue #2864938 by fenstrat, timmillwood, Sam152: Content moderation form...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.4.x and cherry-picked to 8.3.x. Thanks!

I thought about the case in #16, but I think that's a behaviour change/feature as opposed to a bug fix (which I agree this is).

jhedstrom’s picture

Status: Fixed » Closed (fixed)

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