Problem/Motivation

As decided in #2745619: [policy, no patch] Which core entities get revisions?, comments should be converted to be revisionable.

Quoting @webchick from #2745619-9: [policy, no patch] Which core entities get revisions?:

Would allow some recourse for content administrators to go after a malicious user who filled their comment with a bunch of racist garbage to which other users reacted, and then later went back and edited their comment to something more innocent, to dodge being banned.

Proposed resolution

Do it.

Remaining tasks

Review.

User interface changes

None yet, revision support is only enabled at the API level.

API changes

Nope.

Data model changes

Comments are now revisionable.

Issue fork drupal-2880154

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

amateescu created an issue. See original summary.

amateescu’s picture

andypost’s picture

Please update IS about why comments "should" become revisionable by defalt

amateescu’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

It's in the issue summary of the parent issue, but ok, cross-posted here as well.

amateescu’s picture

Title: [PP-3] Convert comments to be revisionable » Convert comments to be revisionable
StatusFileSize
new11.77 KB

No more blockers! Here's a fresh patch for the testbot.

Status: Needs review » Needs work

The last submitted patch, 5: 2880154-5.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new11.77 KB
new809 bytes

Let's fix it.

timmillwood’s picture

Status: Needs review » Reviewed & tested by the community

Look good!

+++ b/core/modules/comment/src/Tests/Update/CommentUpdateTest.php
@@ -71,4 +73,53 @@ public function testPublishedEntityKey() {
+    $comment = $storage->loadRevision($comment->getRevisionId());

Yay, now we can load comment revisions!

tstoeckler’s picture

+++ b/core/modules/comment/comment.post_update.php
@@ -0,0 +1,35 @@
+ * Update custom menu links to be revisionable.

Nit: s/custom menu links/comments/

timmillwood’s picture

StatusFileSize
new565 bytes
new11.8 KB

Oops, missed that.
Could be done on commit, but to keep things moving along, here's a patch.

wim leers’s picture

+++ b/core/modules/rest/tests/src/Functional/EntityResource/Comment/CommentResourceTestBase.php
@@ -123,6 +123,9 @@ protected function getExpectedNormalizedEntity() {
+      'revision_id' => [
+        ['value' => 1],
+      ],
       'uuid' => [

@@ -193,6 +196,11 @@ protected function getExpectedNormalizedEntity() {
+      'revision_created' => [
+        $this->formatExpectedTimestampItemValues((int) $this->entity->getRevisionCreationTime()),
+      ],
+      'revision_user' => [],
+      'revision_log_message' => [],

This is technically a BC break for API-First… I'll let core committers decide here.

timmillwood’s picture

[berdir] timmillwood: I don't think adding new fields violates BC?

berdir’s picture

Content entities are by definition extensible, I don't see how adding more fields is a BC break? That would mean that I could introduce a BC break for Drupal by adding a field in the UI? :)

Then any improvement that adds more stuff to the serialized output would be a BC break too, e.g. exposting things like file url/image style urls, formatted text and so on.

To be clear: This is far from a trivial change, switching out the table storage could break a lot of stuff if people query database tables directly. Although making an entity type revisionable is far less problematic than making it translatable, because we don't really touch the existing tables that much, otherwise a lot of our custom threading queries and so on would be broken too. But those additional fields in the serializer seem like the least of the possible problems IMHO :)

wim leers’s picture

Issue tags: +Needs change record

Content entities are by definition extensible, I don't see how adding more fields is a BC break?

The difference is that this affects every Drupal site using this entity type. Adding more fields is usually a manual operation: if I add additional fields, I'll know I'm changing the data model, and I'll know I'm changing my REST/JSON API responses.

That's a very big difference.

Then any improvement that adds more stuff to the serialized output would be a BC break too, e.g. exposting things like file url/image style urls, formatted text and so on.

Yep! And this is why it's so painful to work on API-First: because every improved normalization requires a BC layer. This is why we have bc_entity_resource_permissions in REST and bc_primitives_as_strings +bc_timestamp_normalizer_unix in Serialization: all these improved normalizations are disabled by default, you have to opt in to them manually.

We'll need similar BC layers for every single thing you mentioned. Without those BC layers, they'd never have been committed.


I do agree that adding more fields is less of a BC break than changing the normalization of a field! But it's still a BC break.

That's why I didn't mark this NW. That's why I said technically a BC break and I'll let core committers decide: because I think this is a reasonable change, with a manageable amount of disruption. But it's still totally possible that this is going to break some decoupled applications. And at minimum, this will need a change record, to warn those sites.

(Also, if it lands, it ought to get an entry in the 8.4.0 release notes!)

timmillwood’s picture

Issue tags: -Needs change record

Added a provisional change record https://www.drupal.org/node/2897893

berdir’s picture

Yep! And this is why it's so painful to work on API-First: because every improved normalization requires a BC layer. This is why we have bc_entity_resource_permissions in REST and bc_primitives_as_strings +bc_timestamp_normalizer_unix in Serialization: all these improved normalizations are disabled by default, you have to opt in to them manually.

Both of those two are different in that they *change* existing structure/behavior. That's not the same as adding propertes/fields that didn't exist before.

We're allowed to add methods to most classes, we're allowed to add the actual fields to the entities (and add and change database tables!), I don't see why we wouldn't be allowed to expose those fields in the serializer. That's how the serializer works by definition IMHO, it dynamically exposes all available/accessible data, as I've said elsewhere, if you require a 100% stable, identical output for your client, then you should write your API. If that is not as clear to you/others as it is to me, then we should document that explicitly on https://www.drupal.org/core/d8-bc-policy. #2716081: BlockContent should have revision_user and revision_created fields and implement RevisionLogInterface is an example that also added additional fields to block_content for example.

But yes, we definitely need a change record here, because as I said, making the entity type revisionable, adding the revision id and other fields is likely going to affect some sites. I'm definitely not arguing against that :)

wim leers’s picture

I'm strongly in favor of documenting the BC promises around REST responses and normalizations at https://www.drupal.org/core/d8-bc-policy! I think that demanding that clients allow additional keys (whether they be fields or properties) to show up in normalizations is a totally fair expectation. I'd love to see that documented there.

All I'm saying here is that this change has the potential to break API clients, and therefore it's technically a BC break, and we should pay close attention to it.

wim leers’s picture

wim leers’s picture

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 10: 2880154-10.patch, failed testing. View results

timmillwood’s picture

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

reroll

timmillwood’s picture

Status: Needs review » Reviewed & tested by the community

Going back to RTBC because I RTBC'd @amateescu's patch in #8, since then I fixed a nitpick and performed a reroll.

@Wim Leers and @Berdir make some good comments regarding backwards compatibility but I'm not sure there is any way around this. The awesome CR updates from @Wim Leers really help, so let's get this in and start to make more things revisionable in 8.4.0

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

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

wim leers’s picture

#22++

timmillwood’s picture

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

As this is already RTBC it should be fine for 8.4.x

xjm’s picture

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

@timmillwood reached out to me about whether this issue is still eligible for 8.4.x. It's a distruptive change, so it should remain filed against 8.5.x generally. During the alpha phase, disruptive changes may be backported at committer discretion after commit. The fact that the issue was RTBC for the past couple weeks is taken into account but does not necessarily mean it will be backported.

In the case of this issue, though, it's a strategic priority, so I would indeed like to backport it if we commit it in time for the beta freeze deadline on Aug. 15, unless other committers raise concerns. Leaving the branch at 8.5.x though; we make the final decision after commit.

Thanks!

xjm’s picture

I talked to @larowlan about this issue and we're a little concerned about the risk and disruption. For example, the related taxonomy issue introduced regressions for the term overview page. It might be best to commit issues like these and #2820848: Make BlockContent entities publishable to 8.5.x early so we have the full development release to test them.

timmillwood’s picture

I can understand the concern for this issue but not for #2820848: Make BlockContent entities publishable. Making BlockContent entities will really help Content Moderation, because it will be possible to archive a block and it will not be visible to users. Currently when BlockContent Entity is archived it is still visible on the site.

timmillwood’s picture

I've been taking a look at possible risks of committing this to 8.4.0:

  • Anonymous users with the permission "Post comments" see a confusing "Revision log message" field.
  • With Content Moderation enabled comments are users with the right permission see the Content Moderation widget.
  • With Content Moderation enabled users with no Content Moderation permissions get comments created as "Draft" (unpublished), even if they have the "Skip comment approval" permission.
  • Bulk operations to "Approve" (publish) comments is blocked by Content Moderation. Approving comments now needs to be done by changing the moderation state to "Published", which doesn't have a bulk operation.

I hate to say this, but pushing to 8.5.x might be a wise choice.

(Although still sure publishing BlockContent entities will be fine for 8.4.0)

xjm’s picture

Status: Reviewed & tested by the community » Needs review

Thanks @timmillwood. Some of those things sound like they might be blocking to me. The first one in particular is a UX regression for a pretty common usecase (anonymous comments). Let's file separate issues for each point and postpone this issue? Setting NR for now.

benjy’s picture

StatusFileSize
new9.76 KB
new13.01 KB

I re-rolled this because I wanted to test the update path. Are the revision user and creation times meant to be pre-filled from the original entities, because they are empty after the update.

screenshot

Status: Needs review » Needs work

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

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new12.21 KB
new3.46 KB

@benjy, I did not consider adding an initial value for those fields but you're right, we probably should :) Here's a patch that does that and also fixes the test fails and coding standards of the reroll.

amateescu’s picture

StatusFileSize
new14.55 KB
new2.57 KB

This patch fixes #29.1 and starts to fix #29.3 but I'd rather wait for #2915398: The moderation_state field is not computed during the creation of a new entity translation. before going any further.

benjy’s picture

Oops, I did actually post a patch with the initialValueFromField fix but I posted it to the wrong issue! Unable to convert a non-translatable entity into a revisionable entity - That worked well for me.

wim leers’s picture

Status: Needs review » Postponed

Per #34.

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

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

matsbla’s picture

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.

Status: Needs review » Needs work

The last submitted patch, 40: drupal-2880154-20-comment-revisions-combined.patch, failed testing. View results

slashrsm’s picture

StatusFileSize
new13.84 KB

This is a 8.6 re-roll of #34.

slashrsm’s picture

StatusFileSize
new13.9 KB

This is a 8.7 re-roll of #34.

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.

patrick.thurmond@gmail.com’s picture

Deleted by user. Sorry, posted this to the wrong issue page. I was working on fixing a patch for ECK and had this issue open as well. Just put it in the wrong place.

patrick.thurmond@gmail.com’s picture

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.

ericmaster’s picture

Status: Needs work » Needs review
StatusFileSize
new14 KB

Last patch had an issue which was breaking configuration synchronization when attempting to enable Content Moderation module. Added a condition to fix that and re-rolled the patch for 8.9.x.

marvil07’s picture

StatusFileSize
new917 bytes

Here an interdiff for the last patch.

Status: Needs review » Needs work

The last submitted patch, 48: 2880154-48-D8.9.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

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.

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

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

sreenivasparuchuri’s picture

I updated to D9, but the patches above do not apply. My current version is 9.2.10. Can some one guide me what need to be changed

steinmb’s picture

Issue tags: +Needs reroll

@sreenivasparuchuri - The patch is just old and needs be rerolled against 9.3.x

andypost’s picture

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

it needs reroll against 9.4.x as 9.3 in release freeze

karishmaamin’s picture

StatusFileSize
new11.08 KB

Re-rolled against 9.4.x. Please review

karishmaamin’s picture

Status: Needs work » Needs review
ranjith_kumar_k_u’s picture

StatusFileSize
new11.16 KB
new3.48 KB

Fixed CS issues.

Kojo Unsui’s picture

I can't apply any of these patches. At the moment I have to stick with Core 9.1.6, and I get the following error

Class 'Drupal\Core\Entity\Sql\SqlContentEntityStorageSchemaConverter' not found in comment_post_update_make_comment_revisionable() (line 24 of /var/  
  www/html/docroot/core/modules/comment/comment.post_update.php). 

and indeed it seems SqlContentEntityStorageSchemaConverter was deprecated in drupal:8.7.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface::updateFieldableEntityType() instead. (source).

Could you point me in the right direction please ?

niles38’s picture

@Kojo Unsui I'm getting the same. I'm going to look into creating another patch to test it with 9.3.6.

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.

sreenivasparuchuri’s picture

StatusFileSize
new11.15 KB

I am using 9.3.13, and i have comment enabled, and after using this patch, when i saved the Comment form display, I am seeing below error

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "hidden" plugin does not exist. Valid plugin IDs for Drupal\Core\Field\WidgetPluginManager are: address_default, address_zone_default, address_country_default, brightcove_inline_entity_form_complex, comment_default, moderation_state_default, cshs, datetime_datelist, datetime_default, daterange_datelist, daterange_default, entity_browser_entity_reference, entity_browser_file, entity_reference_revisions_autocomplete, erviews_options_buttons, erviews_options_select, file_generic, image_image, inline_entity_form_complex, inline_entity_form_simple, link_default, oembed_textfield, media_library_widget, menu_item_extras_view_mode_selector_select, metatag_firehose, path, pega_ecm_entity_reference_drill_down_select, pega_react_multi_select_widget, pegacc_core_industry, pegacc_core_product_area, file_bolt, pegacc_core_suggestion_textfield, poll_choice_default, redirect_source, datetime_timestamp_no_default, scheduler_moderation, select2_entity_reference, select2, text_textarea_with_summary, text_textfield, text_textarea, vote_up_down_widget_type, webform_entity_reference_autocomplete, webform_entity_reference_select, entity_reference_paragraphs, paragraphs, datetime_timestamp, email_default, options_select, string_textarea, uri, string_textfield, language_select, number, boolean_checkbox, entity_reference_autocomplete, options_buttons, entity_reference_autocomplete_tags in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 53 of /var/www/docroot/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).

This is due to the code in core/modules/comment/src/Entity/Comment.php

$fields['revision_log_message']->setDisplayOptions('form', [
      'type' => 'hidden',
    ]);

As per the https://www.drupal.org/node/2801513 , 'type' => 'hidden', causes issue, I am adding new patch where i replaced the that code
Before

$fields['revision_log_message']->setDisplayOptions('form', [
      'type' => 'hidden',
    ]);

After

$fields['revision_log_message']->setDisplayOptions('form', [
      'type' => 'hidden',
    ]);

Status: Needs review » Needs work

The last submitted patch, 63: 2880154-60.patch, failed testing. View results

shubham chandra’s picture

Issue tags: -Needs reroll
StatusFileSize
new11.16 KB

Reroll the patch #59 with Drupal 9.5.x

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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.

dieterholvoet’s picture

Comment #65 discards the changes from #63. I'm going to reroll against #63 and replace the usage of \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchemaConverter with \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface::updateFieldableEntityType().

dieterholvoet’s picture

I started a MR with the patch from #65, rebased and changed the following things:

  • Rebased against 10.1.x
  • Removed the usage of SqlContentEntityStorageSchemaConverter
  • Set initial values for the revision_created and revision_user fields to fix an issue when displaying the revisions overview, as discussed in #2350939.

I also created Comment Revision UI, a module using the work from #2350939: Implement a generic revision UI to implement a revision UI for comments.

dpi’s picture

Left a note on MR.

dieterholvoet’s picture

Commented.

ravi.shankar made their first commit to this issue’s fork.

ravi.shankar’s picture

Addressed Drupal CS issues of MR.

dieterholvoet’s picture

Shouldn't we also add a new_revision field to comment types like node types have, and implement CommentType::shouldCreateNewRevision()?

dieterholvoet’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Seems to be some failures in the MR2872

Also the update hook will need upgrade tests.

Version: 10.1.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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

bobooon’s picture

Probably should update comment_user_cancel() so that revision_user is re-assigned to zero (0) when the author's account is cancelled. I recently ran into an issue where the comment was re-assigned but not the revision. See node_user_cancel() as an example:

node_mass_update($vids, [
  'uid' => 0,
  'revision_uid' => 0,
], NULL, TRUE, TRUE);
bobooon’s picture

StatusFileSize
new17.59 KB

Re-rolled for 10.3.x

jacobupal’s picture

Hey @robbiehobby does your re-roll in #79 include your proposed change in #78?

robbiehobby changed the visibility of the branch 11.x to hidden.

bobooon’s picture

Status: Needs work » Needs review

Opened a new merge request for version 11.x. It includes several bug fixes, improvements, and test adjustments. I did my best to model all changes based on pre-existing solutions in the node revisions implementation.

I haven’t figured out how to resolve the core/modules/jsonapi/tests/src/Functional/CommentTest.php test. Maybe someone who is familiar with that test can jump in? The other failing tests do not seem related to these changes, but I could be wrong.

There probably needs to be new tests created for comment content moderation and for the user cancel changes. Unfortunately, I won’t have time to work on these immediately. Please feel free to jump in if you'd like.

  1. Added the missing revision keys to the config and tests.
  2. Added the revision UI, links, and access control.
  3. Kept the existing comment permission structure with administer comments being the permission that can perform revision CRUD operations.
  4. Removed the base field alter hook because this should be configured in the content moderation workflow rather than in the code.
  5. Added shared table indexes for the comment_revision table.
  6. Created comment_mass_update, a carbon copy of node_mass_update, to primarily handle hook_user_cancel operations gracefully. It includes a new $syncing option to prevent the creation of new revisions when reassigning comments to the anonymous user account. A similar issue for nodes exists at [https://www.drupal.org/project/drupal/issues/3062900](https://www.drupal.org/project/drupal/issues/3062900).
  7. Added a comment moderation handler.
  8. Updated the comment links renderer to be aware of revisions.
bobooon’s picture

StatusFileSize
new129.05 KB
bobooon’s picture

StatusFileSize
new129.06 KB
smustgrave’s picture

Status: Needs review » Needs work

not reviewed yet but pipeline appears to have test failures.

bobooon’s picture

StatusFileSize
new129.05 KB
bobooon’s picture

StatusFileSize
new129.05 KB

Another re-roll so this can be applied to 11.1.x.

xjm’s picture

Amending attribution.

nevergone’s picture

Drupal 11.3.0?

stefan lehmann’s picture

StatusFileSize
new45.32 KB

Re-rolled patch from #89 against 11.3.x.

A lot of the code of the previous patch has made its way into core - so it's now way smaller. I tested that comment revisioning works after applying the patch. However I do not know how to check that all the tests pass after applying the patch.

Do I have to add the commit to the/an MR? Help? :-)

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.

bobooon changed the visibility of the branch main to hidden.

bobooon changed the visibility of the branch 2880154-convert-comments-to to hidden.

bobooon’s picture

I've opened a new merge request for a branch based on the new "main" branch outlined in https://www.drupal.org/about/core/blog/introducing-the-main-branch-for-d.... This was much easier than trying to rebase and resolve numerous conflicts. In addition to these changes:

  1. Removed changes in CommentStorage.php and CommentStorageInterface.php to align with the deprecations outlined in https://www.drupal.org/node/3519187.
  2. Created CommentBulkUpdate.php (a copy of NodeBulkUpdate.php) and updated CommentHooks.php to align with the deprecations outlined in https://www.drupal.org/node/3533315.

You can use https://git.drupalcode.org/project/drupal/-/merge_requests/15359.patch to apply this against Drupal 11.x and 12.x. There are still a couple of minor pipeline test failures to resolve.