Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
/**
* Implementation of hook_token_info().
*/
/**
* Implements hook_token_info().
*/
function feeds_token_info() {
$info = array();
// Node tokens.
$info['tokens']['node']['feed_source'] = array(
'name' => t('Feeds: Source node'),
'description' => t("The node of the feeds source."),
'type' => 'node',
);
return $info;
}
/**
* Implements hook_tokens().
*/
function feeds_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
// Node tokens.
if ($type == 'node' && !empty($data['node'])) {
$node = $data['node'];
// Chained token relationships.
if (($source_tokens = token_find_with_prefix($tokens, 'feed_source')) && ($feed_item = feeds_item_info_load('node', $node->nid)) && ($source_node = node_load($feed_item->feed_nid))) {
$replacements += token_generate('node', $source_tokens, array('node' => $source_node), $options);
}
}
return $replacements;
}
Comments
Comment #1
syp CreditAttribution: syp commentedTested and works perfect.
The feature I was searching for and was there ready to use! :)
Very usefull in conjunction with Pathauto and Node Hierarchy modules.
This piece of code should be include in development release!
Comment #2
Ayesh CreditAttribution: Ayesh commented+1!
Subscribing.
Comment #3
Dave ReidFixed this up and committed the [node:feed-source] token in http://drupalcode.org/project/feeds.git/commit/51600e9
Comment #5
sylvanos CreditAttribution: sylvanos commentedI tried it and i'm unable to make it work. I have node A importing data and creating new nodes B (through node processor). I'm using Automatic NodeTitles to retrieve the title of node A to put it in node B, then I add the date at the end of the title of node B. The date token shows up but not the "feed-source"
Now this could be an issue with Automatic NodeTitles or with Token but I'm able to retrieve many tokens like date or fields but no luck with anything that as to do with [node:feed-source:xxx]
Feeds 7.x-2.0-alpha3
Automatic Nodetitles 7.x-1.0
Token 7.x-1.0-beta2
Drupal 7.2
Comment #6
Dave ReidThe tokens are not available in Feeds 7.x-2.0-alpha3. They're available in 7.x-2.x-dev only right now.
Comment #7
sylvanos CreditAttribution: sylvanos commentedThanks, reinstalled the dev version and cleared the cache: tokens show up. I observed a little bug so I thought I'd document it. Here's how to reproduce it:
1. node A has a feed (JSON)
2. when I import a feed from node A, it creates one feed item (node B) using node processor
3. node B gets its title form the title of node A plus a date token
4. After import, the title of node B looks like this : [node:feed-source:title] - Stats Jun 23 2011 - 11:45
5. When I open node B and save it, then the token is rendered
So the date token gets rendered on import but not the feed-source.
Comment #8
AndrewKWilson CreditAttribution: AndrewKWilson commented@sylvanos I've also noted that the feed-source token does not "render" on import. You must edit and save the new feed item before it will render.
Comment #9
mareks CreditAttribution: mareks commentedI am still having this problem with the latest version of Feeds.