/
localgov_publications.api.php
58 lines (48 loc) · 1.28 KB
/
localgov_publications.api.php
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
55
56
57
58
<?php
/**
* @file
* Hooks provided by the LocalGov Publications module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Alter the menu tree of a publication.
*
* Modules may implement this hook to alter the menu tree of a publication,
* when it's used to build the navigation in the publication_navigation block.
*
* See \Drupal\localgov_publications\Plugin\Block::build() for where this is
* called.
*
* @param array $tree
* The menu tree, as returned by
* \Drupal\book\BookManagerInterfacebookManager::bookTreeAllData()
*/
function hook_localgov_publications_menu_tree_alter(&$tree) {
// This example replaces the title shown in the navigation with a shorter
// title provided by a custom field (lbhf_teaser_title).
foreach ($tree as $item) {
if (!empty($item['below'])) {
hook_localgov_publications_menu_tree_alter($item['below']);
}
if (!isset($item['link']['nid'])) {
continue;
}
$node = Node::load($item['link']['nid']);
if (!$node instanceof NodeInterface) {
continue;
}
if (!$node->hasField('lbhf_teaser_title')) {
continue;
}
$teaserTitle = $node->get('lbhf_teaser_title')->value;
if ($teaserTitle) {
$item['link']['title'] = $teaserTitle;
}
}
}
/**
* @} End of "addtogroup hooks".
*/