1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Builds placeholder replacement tokens for uuid-related data.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_token_info().
|
10
|
*/
|
11
|
function uuid_token_info() {
|
12
|
$tokens = array();
|
13
|
foreach (entity_get_info() as $entity_type => $info) {
|
14
|
if (isset($info['uuid']) && $info['uuid'] == TRUE && !empty($info['entity keys']['uuid'])) {
|
15
|
$token_type = !empty($info['token type']) ? $info['token type'] : $entity_type;
|
16
|
$tokens['tokens'][$token_type][$info['entity keys']['uuid']] = array(
|
17
|
'name' => t('@entity_type UUID', array('@entity_type' => $info['label'])),
|
18
|
'description' => t('The universally unique ID of the @entity', array('@entity' => drupal_strtolower($info['label']))),
|
19
|
);
|
20
|
if (!empty($info['entity keys']['revision uuid'])) {
|
21
|
$tokens['tokens'][$token_type][$info['entity keys']['revision uuid']] = array(
|
22
|
'name' => t('@entity_type revision UUID', array('@entity_type' => $info['label'])),
|
23
|
'description' => t('The universally unique revision ID of the @entity', array('@entity' => drupal_strtolower($info['label']))),
|
24
|
);
|
25
|
}
|
26
|
}
|
27
|
}
|
28
|
return $tokens;
|
29
|
}
|
30
|
|
31
|
/**
|
32
|
* Implements hook_token_info_alter().
|
33
|
*/
|
34
|
function uuid_token_info_alter(&$data) {
|
35
|
foreach (entity_get_info() as $entity_type => $info) {
|
36
|
if (isset($info['uuid']) && $info['uuid'] == TRUE && !empty($info['entity keys']['uuid'])) {
|
37
|
$token_type = !empty($info['token type']) ? $info['token type'] : $entity_type;
|
38
|
if (empty($data['types'][$token_type])) {
|
39
|
unset($data['tokens'][$token_type]);
|
40
|
}
|
41
|
}
|
42
|
}
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* Implements hook_tokens().
|
47
|
*/
|
48
|
function uuid_tokens($token_type, $tokens, $data = array(), $options = array()) {
|
49
|
$replacements = array();
|
50
|
if ($token_type == 'entity') {
|
51
|
$info = entity_get_info($data['entity_type']);
|
52
|
if (isset($info['uuid']) && $info['uuid'] == TRUE && !empty($info['entity keys']['uuid']) && !empty($tokens[$info['entity keys']['uuid']])) {
|
53
|
$replacements[$tokens[$info['entity keys']['uuid']]] = $data['entity']->{$info['entity keys']['uuid']};
|
54
|
if (!empty($info['entity keys']['revision uuid']) && !empty($tokens[$info['entity keys']['revision uuid']])) {
|
55
|
$replacements[$tokens[$info['entity keys']['revision uuid']]] = $data['entity']->{$info['entity keys']['revision uuid']};
|
56
|
}
|
57
|
}
|
58
|
}
|
59
|
return $replacements;
|
60
|
}
|