Problem/Motivation

In core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php, there is no check done if the node bundle is actually under workflow moderation or not and create new revision is forced.

Proposed resolution

We need to have better check here to ensure we don't force this.

Remaining tasks

Review and commit!

User interface changes

Revisions no longer forced for non-moderated bundles.

API changes

None.

Data model changes

None.

Release notes snippet

Comments

nikunjkotecha created an issue. See original summary.

merauluka’s picture

Status: Active » Needs review
StatusFileSize
new3.97 KB

I agree that this behavior is not ideal. I recently ran up against this when reviewing the migration path from Workbench Moderation to Content Moderation. It appears that this behavior was in Workbench Moderation and was carried over into Content Moderation. However, now that moderation can be applied on a per content type basis with custom workflows, I think this deserves another look.

I have created a preliminary patch that checks the if the node type or node being editing is subjected to moderation before enforcing the revisions box to be checked. In testing on my local, this resolved the issue and appears to work well. I'm submitting it here for review by the community.

Status: Needs review » Needs work

The last submitted patch, 2: 2946750-2.patch, failed testing. View results

merauluka’s picture

Status: Needs work » Needs review
StatusFileSize
new3.95 KB

Resubmitting a new patch with the correct relative path.

Status: Needs review » Needs work

The last submitted patch, 4: 2946750-4.patch, failed testing. View results

merauluka’s picture

StatusFileSize
new3.48 KB
new3.5 KB

Rerolled the patch against 8.5.1 and 8.5.x-dev since there was a change to the module in the meantime.

merauluka’s picture

So it appears that this feature is written into the tests on Content Moderation. So the tests will also need to be patched in order to get this feature to pass build tests. Back to the drawing board.

timmillwood’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests
StatusFileSize
new1.83 KB
new5.26 KB

This should fix the failing tests, but I still think this needs more test coverage.

timmillwood’s picture

Status: Needs review » Needs work

Moving back to needs work for more test coverage, specifically around \Drupal\content_moderation\Entity\Handler\NodeModerationHandler::enforceRevisionsEntityFormAlter.

sam152’s picture

+++ b/core/modules/content_moderation/src/Entity/Handler/NodeModerationHandler.php
@@ -44,18 +55,30 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
+    // Load the node definition and bundle name in order to verify that the
+    // current node type is assigned a content moderation workflow. If so then
+    // force the revisions checkbox to be checked and disabled.
+    $bundle = $form['type']['#default_value'];
+    if ($this->moderationInfo->shouldModerateEntitiesOfBundle($this->entityType, $bundle)) {

I think we should actually never call enforceRevisionsEntityFormAlter if the bundle is not being moderated.

That way we fix the issue in one place for all handlers, instead of just for node. Block content will still be broken for example.

sam152’s picture

Status: Needs work » Needs review
StatusFileSize
new6.49 KB
new4.89 KB

We don't actually have to change enforceRevisionsEntityFormAlter, that was working already.

I did however notice we have a redundant check in \Drupal\content_moderation\EntityTypeInfo::formAlter. We check isModeratedEntityEditForm which already checks isModeratedEntity for us, so removing that.

Status: Needs review » Needs work

The last submitted patch, 12: 2946750-12.patch, failed testing. View results

sam152’s picture

Status: Needs work » Needs review
StatusFileSize
new1.52 KB
new6.69 KB

Fixing the test case.

sam152’s picture

StatusFileSize
new5.36 KB

Whoops, removing unrelated file from patch.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

lobsterr’s picture

I have tested it. It works perfectly for me

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

sam152’s picture

Issue tags: -Needs tests
StatusFileSize
new5.49 KB

Reroll.

dercheffe’s picture

Priority: Normal » Major

Hi @all,

I would vote for making this issue a major one, because this problem inflates the DB of a site unnecessarily and can bring massive performance problems.

sam152’s picture

Patch still applies, queuing another test.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

dercheffe’s picture

Status: Needs review » Reviewed & tested by the community

Applied patch in #19 at my Drupal 8.7.8 and it's solving the problem.

catch’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTypeTest.php
@@ -65,6 +65,11 @@ public function testEnablingOnExistingContent() {
 
+    // Check that the 'Create new revision' checkbox is checked and disabled.
+    $this->drupalGet('/admin/structure/types/manage/not_moderated');
+    $this->assertSession()->checkboxChecked('options[revision]');
+    $this->assertSession()->fieldDisabled('options[revision]');
+

Shouldn't this also have a test to ensure the revision checkbox isn't checked/disabled when a bundle isn't moderated?

smaz’s picture

+1 for this fixing the issue for me, not marking as RTBC due to the question about the test above.

webdrips’s picture

+1 #19 applied cleanly to 8.8.5 and seems to work just fine.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

ccjjmartin’s picture

+1 functionally works great, thanks for the effort here all, not marking as RTBC as mentioned above because I agree the test should be updated to include verifying that the checkbox isn't disabled (since that is what I did manually to verify this was working).

sam152’s picture

Issue summary: View changes
StatusFileSize
new895 bytes
new2.15 KB
new5.81 KB

Thanks for the reviews, adding those additional asserts and a red/green patch. Also cleaning up the issue summary a bit.

I decided not to assert the checked status of the revisions checkbox before enabling content moderation, because CM shouldn't be tweaking that and it's a default that comes from the node module.

The last submitted patch, 29: 2946750-29-TEST-ONLY.patch, failed testing. View results

jibran’s picture

Status: Needs review » Reviewed & tested by the community

#24 is address so back to RTBC.

alexpott’s picture

Version: 9.1.x-dev » 9.0.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 30c286f45d to 9.1.x and 09fe2d3e69 to 9.0.x. Thanks!

  • alexpott committed 30c286f on 9.1.x
    Issue #2946750 by Sam152, merauluka, timmillwood, catch: Node revisions...

  • alexpott committed 09fe2d3 on 9.0.x
    Issue #2946750 by Sam152, merauluka, timmillwood, catch: Node revisions...
alexpott’s picture

Title: Node revisions forced even if bundle not under moderation workflow » [backport] Node revisions forced even if bundle not under moderation workflow
Version: 9.0.x-dev » 8.9.x-dev
Status: Fixed » Reviewed & tested by the community

Leaving at backport for 8.9.x and kicking off a test.

alexpott’s picture

Title: [backport] Node revisions forced even if bundle not under moderation workflow » Node revisions forced even if bundle not under moderation workflow
Status: Reviewed & tested by the community » Fixed

Cherry-picked back to 8.9.x

  • alexpott committed 84dca22 on 8.9.x
    Issue #2946750 by Sam152, merauluka, timmillwood, catch: Node revisions...

Status: Fixed » Closed (fixed)

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