Problem/Motivation

This issue was originally discovered by the revision log message field not showing when content moderation is enabled.

The issue stems from if a content type is created without revisions enabled, then content moderation is added, content moderation assumed revisions are enabled, and prevents enabling/disabling revisions, however it doesn't actually enable revisions.

Proposed resolution

Enable Node revisions when enabling moderation on nodes.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

guix created an issue. See original summary.

timmillwood’s picture

Component: content_moderation.module » node system
Issue tags: +Needs tests

Looks like this is an issue with Node system (or maybe Entity system), and not Content Moderation.

It seems the field permissions are handled in \Drupal\Core\Entity\ContentEntityForm::addRevisionableFormFields, I'd need a debug more closely, but some tests for this would be good!

berdir’s picture

Status: Active » Postponed (maintainer needs more info)

That only controls access to the new revision checkbox, that is by design limited.

This is checked in \Drupal\node\NodeAccessControlHandler::checkFieldAccess(), apparently the logic is that the field is visible if a new revision is created by default. Maybe that isn't actually set and just enforced through content moderation? we've had bugs that content_moderation accidently disabled that checkbox, so review your node settings and make sur it is really enabled.

guillaumeduveau’s picture

Status: Postponed (maintainer needs more info) » Active

@timmillwood & @Berdir, thanks for the quick replies.

@Berdir my content type had "Create new revision" checked and grayed out. I made a dump backup, and uninstalled "Content moderation". Then the checkbox is not checked and can be checked. When I check it, and then enable "Content moderation", users can now edit the Entity revision log message.

I did try that with a fresh install of Drupal 8.5 as well and the results are the same.

@Berdir thanks a lot. Would you have any idea how I could "really check" that revision checkbox without uninstalling "Content moderation" ? Because I loose lots of things (transitions and all views, pages etc. that depend on Content moderation). For now I'm gonna try to export my config and import it back after uninstall / reinstall.

@timmillwood is seems that after all this issue belongs to Content moderation.

berdir’s picture

Resaving the form on 8.5 might also fix it, without having to uninstall content moderation. We did actually fix exactly that problem recently. Or maybe we only fixed it for 8.6.x dev, don't remember right now.. #2865223: Node type form alter sets new revision to false on subsequent saves. It was fixed in 8.5.x too.

timmillwood’s picture

Component: node system » content_moderation.module

@guix - Interesting, thanks for the testing.

As you say it's possible to reproduce on a fresh install of 8.5.x it'd be great to get a functional test which also reproduces this. I'm happy to do this, but not sure when I'll get chance, so anyone is welcome to take a look.

timmillwood’s picture

timmillwood’s picture

Issue summary: View changes
Status: Active » Needs review
Issue tags: -Needs tests
StatusFileSize
new2.31 KB
new2.97 KB

Here's a patch and test.

@guix - Are you able to confirm this works for you?
@Berdir - Are you able to check my logic here? I'm not actually testing the revision log field, but the logic used in the access control around the NodeType's new_revision property.

The last submitted patch, 8: 2959611-8-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

berdir’s picture

I'm not sure that is necessary. We already have the logic to enforce the checkbox, it was just broken in the past and this was a result of that bug.

Also, this isn't limited to nodes, block_content_type and media_type have the same feature, but with different names for the setting.

We could think about an update function to fix them once instead of checking every time, but not sure if even that is necessary.

timmillwood’s picture

@Berdir - Yes, the code is there to enfoce the checkbox, but if the content type was created before Content Moderation was enabled, then revisions may not be enabled, and therefore re-saving the content type is the only way to enable. Therefore I think we need something that enables revisions when moderation is enabled.

I didn't realise block content and media had a similar setting in the bundles. I don't believe we cater for that in Content Moderation. It's not a very solid pattern in core (no interface or trait).

berdir’s picture

Yeah, we did add \Drupal\Core\Entity\RevisionableEntityBundleInterface::shouldCreateNewRevision(), but that's just for reading the value, not changing it.

Still don't really like adding more node specific code.

Maybe \Drupal\node\NodeAccessControlHandler::checkFieldAccess() could check with the actual node/entity is about to be created with a new revision instead of just checking its own default value. But not sure if the enforced new revision call is happening early enough. Likely not right now as we, until recently, had the problem that it couldn't be set back to FALSE once set...

sam152’s picture

Status: Needs review » Needs work
+++ b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php
@@ -182,6 +183,16 @@ public function addEntityTypeAndBundle($entity_type_id, $bundle_id) {
+      if ($entity_type_id == 'node') {
+        $bundle = NodeType::load($bundle_id);
+        if ($bundle->isNewRevision() === FALSE) {
+          $bundle->set('new_revision', TRUE);
+          $bundle->save();
+        }
+      }

I think @Berdir is right here, if we have entity type specific code we should move that into the moderation handlers and then try provide as much of a default implementation as we can.

I think we should even go a step further and completely decouple CM code from node and block: #2847629: Move specific entity type handlers to the modules that provide those entity types..

jody lynn’s picture

berdir’s picture

Yes, that issue would be the proper fix, but see my comment #5 for the issue that should have worked around that issue for core? Are you sure you're on the latest version and re-saved the node type settings? The first issue might be a duplicate of that?

jody lynn’s picture

Edit: I'm on 8.5.3 according to composer.lock but I don't seem to have the patch from that issue. Checking history..

jody lynn’s picture

Yeah, looks like that patch hasn't made it into a release yet, hence my fun adventures today ;)

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

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.

Mirroar’s picture

I can confirm the issue still persists in Drupal 8.6, and can be fixed by applying the patch from #2911473: Selected yet disabled individual options from checkboxes element don't persist through save and re-saving the node type edit form.

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

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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.

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

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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.

larowlan’s picture

Also $bundle->isNewRevision() is gone in favour of \Drupal\Core\Entity\RevisionableEntityBundleInterface::shouldCreateNewRevision so that will need updating

kim.pepper’s picture

Issue tags: +#pnx-sprint
mstrelan’s picture

StatusFileSize
new2.97 KB
new697 bytes

This patch address #23. Still needs work as per #13.

meenakshi_j’s picture

Status: Needs work » Needs review
StatusFileSize
new2.99 KB
new930 bytes

Fixed the fails

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

if ($entity_type_id == 'node') {
Won't this only fix it for nodes but what about media, blocks, or other entity types that can have revisions?

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

finex’s picture

I was experiencing this bug: the "create new revision" checked and disabled and the log message input form not available (with content moderation enabled). I've fixed going to the content type settings page (admin/structure/types/manage/XXX) and pressing the save button.

The content moderation module should automatically save the "new_revision" option of the content types managed by a workflow.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

joaopauloscho’s picture

The issue is still present in Drupal 113.10. On a site with Content Moderation, editors (without administer nodes) couldn't see the "Revision log message" field, while admins could.

Setting the field new_revision: true on the moderated content types. Editors then see the field again.