From 51600e96be826254765f13415c5dd58aa17434fb Mon Sep 17 00:00:00 2001 From: Dave Reid <dave@davereid.net> Date: Mon, 16 May 2011 15:30:08 -0500 Subject: [PATCH] Issue #1032640: Added basic token integration. --- feeds.tokens.inc | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 feeds.tokens.inc diff --git a/feeds.tokens.inc b/feeds.tokens.inc new file mode 100644 index 00000000..2078d47e --- /dev/null +++ b/feeds.tokens.inc @@ -0,0 +1,52 @@ +<?php + +/** + * @file + * Builds placeholder replacement tokens for feed-related data. + */ + +/** + * Implements hook_token_info(). + */ +function feeds_token_info() { + // @todo This token could be for any entity type. + $info['tokens']['node']['feed-source'] = array( + 'name' => t('Feed source'), + 'description' => t('The node the feed item was sourced from.'), + 'type' => 'node', + ); + + return $info; +} + +/** + * Implements hook_tokens(). + */ +function feeds_tokens($type, $tokens, array $data, array $options) { + $replacements = array(); + + $sanitize = !empty($options['sanitize']); + + if ($type == 'node' && !empty($data['node'])) { + $node = $data['node']; + + foreach ($tokens as $name => $original) { + switch ($name) { + case 'feed-source': + if (!empty($node->feed_nid) && $feed_source = node_load($node->feed_nid)) { + $replacements[$original] = $sanitize ? check_plain($feed_source->title) : $feed_source->title; + } + break; + } + } + + // Chained node token relationships. + if ($feed_source_tokens = token_find_with_prefix($tokens, 'feed-source')) { + if (!empty($node->feed_nid) && $feed_source = node_load($node->feed_nid)) { + $replacements += token_generate('node', $feed_source_tokens, array('node' => $feed_source), $options); + } + } + } + + return $replacements; +} -- GitLab