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.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | drupal-tokens_are_not_replaced-1671420-12-D8.patch | 513 bytes | sagar ramgade |
| #9 | token_default_state-1671420-9.patch | 568 bytes | novitsh |
| #3 | node_empty_summary_token-1671420.patch | 472 bytes | novitsh |
| node.empty-summary-token.patch | 1.14 KB | levialliance |
Comments
Comment #1
damienmckennaThere's a patch, so it needs to be reviewed.
Comment #2
darol100 commentedThis patch does not apply anymore.
error: patch failed: modules/node/node.tokens.inc:135error: modules/node/node.tokens.inc: patch does not applyComment #3
novitsh commentedHere's a newer version. Could you please verify?
Comment #4
novitsh commentedComment #5
darol100 commentedLooks fine to me.
Comment #6
damienmckennaComment #7
David_Rothstein commentedFrom 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.
Comment #8
David_Rothstein commentedComment #9
novitsh commentedNon-tested first attempt patch.
Comment #10
novitsh commentedComment #12
sagar ramgade commentedPatch attached for D8.
Comment #13
novitsh commentedSeems to work for me. RTBC?
Comment #16
novitsh commentedComment #18
xjmThanks @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?
Comment #19
David_Rothstein commentedComment #25
stevenpatzCan 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.
Comment #31
pameeela commentedCame 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.
Comment #33
pameeela commentedClosing since there hasn't been any further action. It's no longer outputting the token if the body field doesn't exist.