From 207882214200d22b055fe847dd9cd136e4804b71 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Sat, 1 Oct 2011 23:21:49 +0900
Subject: [PATCH] Issue #1178580 by Dave Reid: Fixed PHP notices with
 [node:summary], [node:body], or [comment:body] if there is no body field or
 language mismatch.

---
 modules/comment/comment.tokens.inc | 8 +++++---
 modules/node/node.tokens.inc       | 6 +++---
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/modules/comment/comment.tokens.inc b/modules/comment/comment.tokens.inc
index d62b7e2f8f05..c495ec35d663 100644
--- a/modules/comment/comment.tokens.inc
+++ b/modules/comment/comment.tokens.inc
@@ -155,9 +155,11 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
           break;
 
         case 'body':
-          $item = $comment->comment_body[LANGUAGE_NONE][0];
-          $instance = field_info_instance('comment', 'body', 'comment_body');
-          $replacements[$original] = $sanitize ? _text_sanitize($instance, LANGUAGE_NONE, $item, 'value') : $item['value'];
+          if ($items = field_get_items('comment', $comment, 'comment_body', $language_code)) {
+            $instance = field_info_instance('comment', 'body', 'comment_body');
+            $field_langcode = field_language('comment', $comment, 'comment_body', $language_code);
+            $replacements[$original] = $sanitize ? _text_sanitize($instance, $field_langcode, $items[0], 'value') : $items[0]['value'];
+          }
           break;
 
         // Comment related URLs.
diff --git a/modules/node/node.tokens.inc b/modules/node/node.tokens.inc
index b6bafc639077..491ec81c4094 100644
--- a/modules/node/node.tokens.inc
+++ b/modules/node/node.tokens.inc
@@ -135,11 +135,11 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr
 
         case 'body':
         case 'summary':
-          if (!empty($node->body)) {
-            $item = $node->body[$node->language][0];
+          if ($items = field_get_items('node', $node, 'body', $language_code)) {
             $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];
+            $field_langcode = field_language('node', $node, 'body', $language_code);
+            $replacements[$original] = $sanitize ? _text_sanitize($instance, $field_langcode, $items[0], $column) : $items[0][$column];
           }
           break;
 
-- 
GitLab