Follow-up to #1885962-14: Comment tokens should use entity translation API

Problem/Motivation

Currently comment entity token for "comment_body" is "body" so could have collision with some contrib provided field, and brings confusion because token is misnames.
Also this blocks automatic token generation.

Proposed resolution

Change token name to "comment_body" as field named before RC, fix tests

Remaining tasks

Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Update the issue summary Instructions
Update the issue summary noting if allowed during the beta Instructions
Add automated tests Instructions
Update the patch to incorporate feedback from reviews (include an interdiff) Instructions

User interface changes

no

API changes

no, just a token name

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because we are renaming a token.
Issue priority Normal because while there is no direct problem with using "body" as token, it could lead to collisions with contrib and possibly confuse people. Changing it to comment_body is the sane thing to do.
Unfrozen changes None
Prioritized changes The main goal of this patch is improving UX and DX.
Disruption None

Comments

andypost’s picture

Status: Active » Needs review
StatusFileSize
new638 bytes

Let's see how much broken

Status: Needs review » Needs work

The last submitted patch, 1: 2423341-comment_body_token-1.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new1.53 KB
new2.16 KB

Fixed tests

vijaycs85’s picture

StatusFileSize
new2.22 KB

re-rolling #4. Changes looks good. +1 to RTBC.

Status: Needs review » Needs work

The last submitted patch, 5: 2423341-5.patch, failed testing.

vijaycs85’s picture

Status: Needs work » Needs review
StatusFileSize
new2.77 KB
new859 bytes
xito’s picture

Assigned: Unassigned » xito
Issue tags: -Entity Field API +Entity Field API DUGBE0609
mon_franco’s picture

Issue tags: -Entity Field API DUGBE0609 +Entity Field API, +DUGBE0609
xito’s picture

Assigned: xito » Unassigned

I checked the issue and in my opinion it is fine to be on RTBC

Anonymous’s picture

Status: Needs review » Needs work
Issue tags: +Needs beta evaluation

The patch looks good to me, but there I found two more occurrences:
- in EmailAction::buildConfigurationForm()
- in MessageAction::buildConfigurationForm()

We probably want to fix those as well.

rajeevk’s picture

Status: Needs work » Needs review
StatusFileSize
new4.88 KB
new2.11 KB
andypost’s picture

looks good to go, upgrade path is not needed
but we still need to evaluate this for beta

Anonymous’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs beta evaluation

Ok, great! Let's get this in.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 12: 2423341-12.patch, failed testing.

The last submitted patch, 12: 2423341-12.patch, failed testing.

Anonymous’s picture

Issue tags: +Needs reroll, +Novice

So it seems this needs a reroll.

$ git apply --index patches/2423341-12.patch
error: patch failed: core/modules/action/src/Plugin/Action/EmailAction.php:185
error: core/modules/action/src/Plugin/Action/EmailAction.php: patch does not apply
error: patch failed: core/modules/action/src/Plugin/Action/MessageAction.php:78
error: core/modules/action/src/Plugin/Action/MessageAction.php: patch does not apply
error: patch failed: core/modules/comment/comment.tokens.inc:157
error: core/modules/comment/comment.tokens.inc: patch does not apply
error: patch failed: core/modules/comment/src/Tests/CommentTokenReplaceTest.php:58
error: core/modules/comment/src/Tests/CommentTokenReplaceTest.php: patch does not apply
rumburak’s picture

Status: Needs work » Needs review
StatusFileSize
new4.99 KB

Patch re-rolled. Please pay special attention in review, since this is my first re-roll.

vijaycs85’s picture

Issue tags: -Needs reroll
Anonymous’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Novice

This patch applies cleanly again. Thanks!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 18: rename_body_comment-2423341-18.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new4.71 KB
larowlan’s picture

Status: Needs review » Reviewed & tested by the community

thanks

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 22: rename_body_comment-2423341-24.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 22: rename_body_comment-2423341-24.patch, failed testing.

andypost’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new4.71 KB

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: rename_body_comment-2423341-27.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 27: rename_body_comment-2423341-27.patch, failed testing.

Status: Needs work » Needs review
daffie’s picture

Status: Needs review » Reviewed & tested by the community

It all looks good to me.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

How is this any different from the node body token? What makes comment different? I guess it is because the field is actually called comment_body. Hmmm.. this seems a not nice break to be making now. If someone is using the comment body token this will be a hard break.

jonathanshaw’s picture

Needs a discussion on what to do given that D8.0 was missed, and this causes a hard BC break in UX for anyone using the [body] token for comments.

Strategies:
Soft break: allow [comment_body] as a permitted token alongside [body], mark and document [body] as deprecated
Hard break: allow [comment_body], stop [body]

Options:
1) Soft-break now, hard break D8.1
2) Soft-break now, hard break D9
3) Soft break D8.1, hard break D9
4) No soft break, hard break D8.1
5) No soft break, hard break D9

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

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

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

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

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

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.

tr’s picture

Version: 8.6.x-dev » 8.8.x-dev
StatusFileSize
new4.84 KB

Re-rolled #27 so that it applies to current HEAD.

As mentioned in #33 and #34, we need to decide when and how we can make a token change like this in our release cycle.

dpi’s picture

StatusFileSize
new8.47 KB
new8.49 KB

Some ideas on the direction forward, since this issue seems to be stalled due to how to approach deprecation:

  • Trigger deprecation warnings when calling [comment:body], this shouldn't impact production code.
  • Switch over existing code/testing/usage to use [comment:comment_body] (above patch does this), and add a deprecated body token.
  • Leave [comment:body] token in codebase until 9.x, which is only available with a feature flag.
  • Existing sites have an update path to turn on this flag. New sites don't get this flag.
  • Feature flag is immediately marked as deprecated.

I think these changes would be the safest way to resolve this issue, whilst being able to do it within 8.x lifecycle.

This approach also allows sites to implement a new [comment:body] token without triggering deprecations.

Patch implements above.
Updated modified lines to fix CS issues (\t() to $this->t());

Status: Needs review » Needs work

The last submitted patch, 42: 2423341-comment-body-token-42.patch, failed testing. View results

dpi’s picture

Status: Needs work » Needs review
StatusFileSize
new9.19 KB
new725 bytes

Added to acceptable deprecations.

andypost’s picture

Not sure the new const makes sense to introduce

dpi’s picture

The constant is neither here nor there, its immediately deprecated to remove for 9.x , or could easily be substituted to a plain string.

andypost’s picture

@dpi yes, we trying to get rid of it (constants) in other issues and it's really hard to add deprecation testing for constant

larowlan’s picture

  1. +++ b/core/modules/comment/comment.install
    @@ -260,3 +260,10 @@ function comment_update_8701() {
    +  \Drupal::state()->set(\COMMENT_LEGACY_BODY_TOKEN, TRUE);
    

    Yeah, I agree with @andypost, lets not introduce this at a global level

  2. +++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
    @@ -140,6 +140,7 @@ trait DeprecationListenerTrait {
    +      '[comment:body] token will no longer return value of [comment:comment_body].',
    

    We can't do this here, we have to clean up the uses as part of the patch.

dpi’s picture

The usage is only triggered by tests. I introduced the legacy behaviour for any existing usage of the token, which could be anywhere. Any advice for ignoring the warning for tests only?

larowlan’s picture

Add @legacy annotation to the test if its testing legacy behaviour, this will ignore deprecations

dpi’s picture

StatusFileSize
new4.71 KB
new7.98 KB

Thanks @andypost + @larowlan for the feedback.

Addressed in attached.

berdir’s picture

Status: Needs review » Needs work

Deprecations like this are hard because it's challenging to reach the people we want to tell and tell them what they need to do.

One thing is that the feature-flag is IMHO unnecessary. Deprecation messages on production are not a concern, yes it does have an overhead, but so are all others, many of which are very likely called *way* more often.

The feature flag would also break examples where this token is used in default configuration, e.g. a module like comment_notify. That would mean that it would be impossible for that module to be compatible with 8.7 and 8.8, assuming it is committed there. So that's definitely not an option.

At most, that flag could hide the token info, which currently it doesn't even do yet. And even that is problematic because with token.module, some places even validate the used tokens and that they exist.

At the same time, a @trigger_error() doesn't reach site admins that put this token anywhere in configuration or even content, because it will never show for them. I'm not really sure what to do about that, to be honest. Sometimes if it's a single configuration that we deprecate (e.g. temporary file directory to settings instead of config), we add a requirements hook to tell users that they need to update their configuration but here, we don't even know where it is used, at best we could somehow log that it was used and tell about that.

+++ b/core/modules/comment/tests/src/Functional/CommentTokenReplaceTest.php
@@ -18,6 +18,7 @@ use Drupal\user\Entity\User;
  *
  * @group comment
+ * @group legacy
  */
 class CommentTokenReplaceTest extends CommentTestBase {

The instructions here were a bit unclear.

We don't want to make existing tests that are also testing other things as @legacy, it should be a new one, e.g. CommentDeprecatedTokenReplaceTest.

Also, @legacy needs to be combined with at least one @expectedDeprecation annotation on the test method, it's a) testing that the old logic still works and b) that the specific trigger_error() also works.

+++ b/core/modules/comment/comment.tokens.inc
@@ -168,6 +172,14 @@ function comment_tokens($type, $tokens, array $data, array $options, BubbleableM
+          }
+          // Continues to 'comment_body' token if legacy token behavior is on.
+          @trigger_error('[comment:body] token will no longer return value of [comment:comment_body].', E_USER_DEPRECATED);

Deprecation messages need to follow a specific format, example:

@trigger_error('drupal_render_root() is deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Render\RendererInterface::renderRoot() instead. See https://www.drupal.org/node/2912696', E_USER_DEPRECATED);

* deprecation in which version
* when will it be removed
* Link to change record.

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.

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.

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.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.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.

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.

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.

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.