I'm getting the message in the Title bar when I edit a node.

Any help? Please, CC

#39 node_summary_token.zip1.29 KBnetbear
#9 1178580-body-field-tokens.patch2.06 KBDave Reid
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1178580-body-field-tokens_0.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.
[ View ]
#4 1178580-body-field-tokens.patch1.84 KBDave Reid
PASSED: [[SimpleTest]]: [MySQL] 32,186 pass(es).
[ View ]



Project:Token» Drupal core
Version:7.x-1.0-beta2» 8.x-dev
Component:Code» node system
Issue tags:+token

This looks like it is a problem with Drupal core's token integration for the [node:body] and [node:summary] tokens for when a node type does not contain a body field.

Title:Notice: Undefined offset: 0 in node_tokens() (line 140 of ../modules/node/node.tokens.inc).PHP notices with [node:summary], [node:body], or [comment:body] if there is no body field
Component:node system» token system
Assigned:Unassigned» Dave Reid

Status:Active» Needs review
new1.84 KB
PASSED: [[SimpleTest]]: [MySQL] 32,186 pass(es).
[ View ]

Marked #1277472: Undefined index: de in node_tokens() as a duplicate of this issue.

Title:PHP notices with [node:summary], [node:body], or [comment:body] if there is no body fieldPHP notices with [node:summary], [node:body], or [comment:body] if there is no body field or language mismatch

Marked #1278480: Notice: Undefined index in node_tokens() as a duplicate of this issue.

new2.06 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1178580-body-field-tokens_0.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.
[ View ]

Revised patch that attempts to use the language code passed in via $options['language']->language when using field_get_items() and _text_sanitize().

Will I be able to use this patch even though I am using drupal 7.8 and the patch details says 8.x for the branch core?

This works fine on my 7.8

Thanks yeha and Dave Reid for your help so far. However, for the life of me I am yet to find a topic that explains to a newbie on how to install a ptch on a webserver like hostmonster. everything i see is how to do it on a local computer. I installed dush thinking that would help only to find out that it didn't. I installed gitsmart and got nowhere either. I am stumped.

when i tried to patch tokens.module i get the following:

patching file token.module
Hunk #1 FAILED at 155.
1 out of 1 hunk FAILED -- saving rejects to file token.module.rej
can't find file to patch at input line 24
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
|diff --git a/modules/node/node.tokens.inc b/modules/node/node.tokens.inc
|index b6bafc6..491ec81 100644
|--- a/modules/node/node.tokens.inc
|+++ b/modules/node/node.tokens.inc
File to patch:

WHOHOOOOOOOO! finally. patch successfull and bug is gone.

I finally found how to patch but was patching in the tokens folder instead of the node folder.
Thanks everyone. It goes to show that resilience goes a long way.

#9: 1178580-body-field-tokens.patch queued for re-testing.

Yes, it works also on 7.8... thank you for patching it!

Thanks for patching! Works fine on 7.8 for me! :-)

Status:Needs review» Reviewed & tested by the community

Bug confirmed, fix looks fine, patch tested, testbot happy, so...

Version:8.x-dev» 7.x-dev

Only thing that looked a bit iffy here was _text_sanitize() but we're already using that - is there an issue somewhere to avoid having to call the private function?

Committed and pushed to 8.x. Moving to 7.x for webchick.

Status:Reviewed & tested by the community» Fixed

Committed and pushed to 7.x. Thanks!

I got the same problem, but I don't understand how to apply the patch.

When I google "apply a patch to drupal 7" I get alot of results, but most tutorials are on Windows/Mac or with Git.

My site already runs online and I can only access it via DirectAdmin or FileZilla.

Handy links or suggestions are welcome!

Status:Fixed» Needs review
Issue tags:-token

#9: 1178580-body-field-tokens.patch queued for re-testing.

Status:Needs review» Needs work
Issue tags:+token

The last submitted patch, 1178580-body-field-tokens.patch, failed testing.

Ok, I found an article on "manuelly applying a patch" and it works.

Go to modules/node/node.tokens.inc

line 135-144:

case 'body':
case 'summary':
if (!empty($node->body)) {
$item = $node->body[$node->language][0];
$column = ($name == 'body') ? 'value' : 'summary';
$instance = field_info_instance('node', 'body', $node->type);
$replacements[$original] = $sanitize ? _text_sanitize($instance, $node->language, $item, $column) : $item[$column];

change this with:

case 'body':
case 'summary':
if ($items = field_get_items('node', $node, 'body', $language_code)) {
$column = ($name == 'body') ? 'value' : 'summary';
$instance = field_info_instance('node', 'body', $node->type);
$field_langcode = field_language('node', $node, 'body', $language_code);
$replacements[$original] = $sanitize ? _text_sanitize($instance, $field_langcode, $items[0], $column) : $items[0][$column];

Save upload and the body of my nodes shows up.


This is the best article about patching !


Status:Needs work» Fixed

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Status:Closed (fixed)» Needs work

+++ b/modules/comment/comment.tokens.inc
@@ -155,9 +155,11 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
+          if ($items = field_get_items('comment', $comment, 'comment_body', $language_code)) {

field_get_items() is better than $node->language but will need to be fixed with anything coming out from #1260640: Improve field language API DX.

+++ b/modules/node/node.tokens.inc
@@ -135,11 +135,11 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr
+          if ($items = field_get_items('node', $node, 'body', $language_code)) {

As above.

-25 days to next Drupal core point release.

Issue tags:+Needs tests

We'll need tests to cover this bug, I guess.

Not sure how #27 is an actual reason to re-open a closed issue...

Status:Needs work» Closed (fixed)

Please file a separate issue.

The reason is simply that this cannot be considered fixed, since sites exploiting translatable fields might now get the wrong token values under certain conditions.

Shouldn't field_language gracefully fallback since it's used by field_get_items()? If this is a failure in the field API then it should be fixed there.

As pointed out in #1260640: Improve field language API DX, field_get_items() returns the field values in the current content language (or fallback values), which may lead to an inconsistent behavior if the current language differs from the node language. Say I save the same node first with current language 'en' and then with current language 'it' and body values are available for both languages: token values will be english and italian respectively, which may be a problem if the resulting value is going to be stored.

I wanted to give this a bump as I'm still experiencing a related error message, using core 7.19.

Notice: Undefined index: summary in node_tokens() (line 142 of .../modules/node/node.tokens.inc).

I see that the patches in #24 and #27 made it into core, but if you have a node summary but no "body" field, then this warning still pops up often. It doesn't seem to have an effect (i.e. not a harmful bug) as mentioned above, but it would be great not to have a page full of warnings in my watchdog.

Any suggestions?

I confirm, also have this problem in drupal 7.19
Notice: Undefined index: summary in node_tokens() (line 142 of .../modules/node/node.tokens.inc).

I flushed token cache with call to function token_clear_cache(); and notices are gone for now.

No, the problem is back now, flushing token cache didn't help.

I too am having this issue, does anyone know a work around? I don't want to disable messages but that's the only thing I can think of! Any help would be appreciated.

new1.29 KB

I found a little module for quick solving of the problem http://drupal.org/project/node_summary_token

Also found another snippet in this comment http://drupal.org/node/1295524#comment-5825254
and created module from it, attached it to my comment.