This is really a follow on from #1178580: PHP notices with [node:summary], [node:body], or [comment:body] if there is no body field or language mismatch. Like that issue, it applies to [node:summary], [node:body]. If you use [node:body] on a node that has no body field, that issue fixed the errors but the solution was to leave the token unreplaced.

It seems to make far more sense to me to replace the token with an empty string rather that leave it unchanged. For example, if you try to use [node:summary] in http://drupal.org/project/metatag/ for the meta description for nodes, then for nodes (or comments) with no body I would expect the token to give me back an empty string rather than "[node:summary]".

Am happy to be corrected, but I can see no situation where you would not want an empty string. Attached is a patch that implements this.

As a more obscure case, this situation also arises if the body field does exist but has been changed from the default to a multivalue field that is empty for the node in question.

Comments

damienmckenna’s picture

Status: Active » Needs review

There's a patch, so it needs to be reviewed.

darol100’s picture

Component: node.module » ajax system
Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll

This patch does not apply anymore.

  • error: patch failed: modules/node/node.tokens.inc:135
  • error: modules/node/node.tokens.inc: patch does not apply
novitsh’s picture

StatusFileSize
new472 bytes

Here's a newer version. Could you please verify?

novitsh’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
darol100’s picture

Status: Needs review » Reviewed & tested by the community

Looks fine to me.

damienmckenna’s picture

Issue tags: +Needs tests
David_Rothstein’s picture

Version: 7.x-dev » 8.0.x-dev
Category: Feature request » Bug report
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs backport to D7

From the code, it looks like this issue probably affects Drupal 8 also. Has anyone checked?

And yeah, tests would go a long way here, as it would help be clear on exactly what we're fixing.

David_Rothstein’s picture

Component: ajax system » token system
novitsh’s picture

StatusFileSize
new568 bytes

Non-tested first attempt patch.

novitsh’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 9: token_default_state-1671420-9.patch, failed testing.

sagar ramgade’s picture

Status: Needs work » Needs review
StatusFileSize
new513 bytes

Patch attached for D8.

novitsh’s picture

Status: Needs review » Reviewed & tested by the community

Seems to work for me. RTBC?

The last submitted patch, 9: token_default_state-1671420-9.patch, failed testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 12: drupal-tokens_are_not_replaced-1671420-12-D8.patch, failed testing.

novitsh’s picture

Status: Needs work » Reviewed & tested by the community

The last submitted patch, 9: token_default_state-1671420-9.patch, failed testing.

xjm’s picture

Status: Reviewed & tested by the community » Needs work

Thanks @Sagar Ramgade for providing a Drupal 8 patch.

We still need tests for this.

I'm tagging for subsystem maintainer review because I'm actually not sure what the normal behavior is when a token is not defined, or in a situation where it might or might not be available. Maybe @Dave Reid can help clarify the expectation?

David_Rothstein’s picture

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.

stevenpatz’s picture

Version: 8.5.x-dev » 8.6.x-dev
Priority: Normal » Major

Can we take a new look at this? I have a site where we have Body with Summary turned on. 99% of our Summary fields though are empty, so we need the Meta Description tag to be populated with a trimmed version of the body. With the patch in comment #12 ( https://www.drupal.org/project/drupal/issues/1671420#comment-10439947 ) the Description tag gets filled in, with the Summary if it's populated or with a trimmed version of the Body.

Right now I'd need to patch Core to get this to work, which is far from ideal.

I can re-roll and test the patch in 12, but need to know if this is something we can get fixed.

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.

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.

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.

pameeela’s picture

Status: Needs work » Postponed (maintainer needs more info)

Came across this issue looking for something related, but I don't think that this specific issue still occurs?

E.g. given a node with no body field, the tokens [node:body] and [node:summary] do not output anything for these nodes, which I assume means they are empty strings?

Not going to close in case I am missing something.

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.

pameeela’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
Issue tags: +Bug Smash Initiative

Closing since there hasn't been any further action. It's no longer outputting the token if the body field doesn't exist.