summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reid2011-08-22 22:30:11 (GMT)
committer Dave Reid2011-08-22 22:30:22 (GMT)
commit373f6e6000a9ef5f40c18d6a5f571904e6d6c3af (patch)
treeaa4302fb3f6725911334d9ad80ecbc9d92eca132
parentb50ec03a2172ae207d604c3d5adcae3e314155ff (diff)
Issue #1256860: Fixed PHP notice with example tokens on nodes or comments without body fields.
-rw-r--r--token_example/token_example.tokens.inc24
1 files changed, 16 insertions, 8 deletions
diff --git a/token_example/token_example.tokens.inc b/token_example/token_example.tokens.inc
index d62a329..a15bf31 100644
--- a/token_example/token_example.tokens.inc
+++ b/token_example/token_example.tokens.inc
@@ -96,16 +96,20 @@ function token_example_tokens($type, $tokens, array $data = array(), array $opti
foreach ($tokens as $name => $original) {
switch ($name) {
case 'body-format':
- $format = filter_format_load($node->body[LANGUAGE_NONE][0]['format']);
- $replacements[$original] = $sanitize ? filter_xss($format->name) : $format->name;
+ if ($items = field_get_items('node', $node, 'body')) {
+ $format = filter_format_load($items[0]['format']);
+ $replacements[$original] = $sanitize ? filter_xss($format->name) : $format->name;
+ }
break;
}
}
// Chained token relationships.
if ($format_tokens = token_find_with_prefix($tokens, 'body-format')) {
- $body_format = filter_format_load($node->body[LANGUAGE_NONE][0]['format']);
- $replacements += token_generate('format', $format_tokens, array('format' => $body_format), $options);
+ if ($items = field_get_items('node', $node, 'body')) {
+ $body_format = filter_format_load($items[0]['format']);
+ $replacements += token_generate('format', $format_tokens, array('format' => $body_format), $options);
+ }
}
}
@@ -116,16 +120,20 @@ function token_example_tokens($type, $tokens, array $data = array(), array $opti
foreach ($tokens as $name => $original) {
switch ($name) {
case 'body-format':
- $format = filter_format_load($comment->comment_body[LANGUAGE_NONE][0]['format']);
- $replacements[$original] = $sanitize ? filter_xss($format->name) : $format->name;
+ if ($items = field_get_items('comment', $comment, 'comment_body')) {
+ $format = filter_format_load($items[0]['format']);
+ $replacements[$original] = $sanitize ? filter_xss($format->name) : $format->name;
+ }
break;
}
}
// Chained token relationships.
if ($format_tokens = token_find_with_prefix($tokens, 'body-format')) {
- $body_format = filter_format_load($comment->comment_body[LANGUAGE_NONE][0]['format']);
- $replacements += token_generate('format', $format_tokens, array('format' => $body_format), $options);
+ if ($items = field_get_items('comment', $comment, 'comment_body')) {
+ $body_format = filter_format_load($items[0]['format']);
+ $replacements += token_generate('format', $format_tokens, array('format' => $body_format), $options);
+ }
}
}