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

Any help? Please, CC

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

CharlieCastle’s picture

Anyone?

Dave Reid’s picture

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.

Dave Reid’s picture

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
Dave Reid’s picture

Status: Active » Needs review
FileSize
1.84 KB
Dave Reid’s picture

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

Dave Reid’s picture

Title: PHP notices with [node:summary], [node:body], or [comment:body] if there is no body field » PHP notices with [node:summary], [node:body], or [comment:body] if there is no body field or language mismatch
Dave Reid’s picture

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

Dave Reid’s picture

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

jagmeister’s picture

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?

yeha’s picture

This works fine on my 7.8

jagmeister’s picture

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.

jagmeister’s picture

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:

jagmeister’s picture

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.

boryna’s picture

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

RedJane’s picture

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

Anonymous’s picture

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

oriol_e9g’s picture

Status: Needs review » Reviewed & tested by the community

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

catch’s picture

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.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 7.x. Thanks!

dothraki’s picture

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!

dothraki’s picture

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.

dothraki’s picture

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];
}
break;

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];
}
break;

Save upload and the body of my nodes shows up.

http://drupal.org/node/34422

This is the best article about patching !

greetz

catch’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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

plach’s picture

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.

plach’s picture

Issue tags: +Needs tests

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

Dave Reid’s picture

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

Dave Reid’s picture

Status: Needs work » Closed (fixed)

Please file a separate issue.

plach’s picture

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.

Dave Reid’s picture

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.

plach’s picture

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.

storytellerjeff’s picture

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?

netbear’s picture

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).

netbear’s picture

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

netbear’s picture

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

Anonymous’s picture

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.

netbear’s picture

FileSize
1.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.