-
Notifications
You must be signed in to change notification settings - Fork 1
/
idc_ui_module.tokens.inc
45 lines (38 loc) · 1.13 KB
/
idc_ui_module.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
<?php
/**
* Implements hook_token_info().
*/
function idc_ui_module_token_info() {
$info = [];
$info['types']['idc_token_group'] = array(
'name' => t('IDC tokens'),
'description' => t('IDC custom tokens'),
);
$info['tokens']['idc_token_group']['repo_item_parent'] = array(
'name' => t('Repository item parent collection'),
'description' => t('Get the parent collection of the repository item on this page.'),
);
return $info;
}
/**
* Implements hook_tokens().
*/
function idc_ui_module_tokens($type, $tokens, array $data, array $options, \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata) {
$replacements = [];
if ($type == 'idc_token_group') {
foreach ($tokens as $name => $original) {
switch ($name) {
case 'repo_item_parent':
$parents = \Drupal::routeMatch()
->getParameter('node')
->get('field_member_of')
->referencedEntities();
if (!empty($parents) && count($parents) > 0) {
$replacements[$original] = array_values($parents)[0]->id();
}
break;
}
}
}
return $replacements;
}