-
Notifications
You must be signed in to change notification settings - Fork 12
/
feeds.tokens.inc
54 lines (42 loc) · 1.42 KB
/
feeds.tokens.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?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();
if ($type == 'node' && !empty($data['node']) && !empty($data['node']->nid)) {
$sanitize = !empty($options['sanitize']);
$feed_source_tokens = token_find_with_prefix($tokens, 'feed-source');
$feed_source_token_exists = array_key_exists('feed-source', $tokens);
if (empty($feed_source_tokens) && !$feed_source_token_exists) {
return $replacements;
}
$feed_nid = feeds_get_feed_nid($data['node']->nid, 'node');
if ($feed_nid && $feed_source = node_load($feed_nid)) {
if (isset($tokens['feed-source'])) {
$replacements[$tokens['feed-source']] = $sanitize ? check_plain($feed_source->title) : $feed_source->title;
}
// Chained node token relationships.
if (!empty($feed_source_tokens)) {
$replacements += token_generate('node', $feed_source_tokens, array('node' => $feed_source), $options);
}
}
}
return $replacements;
}