-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtide_core.api.php
More file actions
56 lines (51 loc) · 1.83 KB
/
Copy pathtide_core.api.php
File metadata and controls
56 lines (51 loc) · 1.83 KB
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
<?php
/**
* @file
* Hooks provided by the Tide Core module.
*/
use Drupal\node\NodeInterface;
/**
* @addtogroup hooks
* @{
*/
/**
* Alter the breadcrumb trail tide_core computes for a node.
*
* Tide Core builds a simple, menu-based breadcrumb trail for a node (the
* "Home" crumb followed by the node's ancestor menu links) and passes it
* through this alter before it is consumed — most notably by the schema.org
* BreadcrumbList that feeds the node's JSON-LD computed field.
*
* This is the supported override point: a module can replace the baseline
* trail with its own calculation (for example a taxonomy-driven or
* multi-site trail) and thereby change the JSON-LD output, without tide_core
* needing to know about it.
*
* @param array $trail
* The breadcrumb trail, an ordered list of crumbs. Each crumb is an array
* with:
* - title: (string) The visible label of the crumb.
* - url: (string) The crumb URL. May be a site-relative path (with a
* /site-XXXX/ prefix); downstream consumers normalise it to an absolute
* front-end URL. The current node is NOT included — consumers append it.
* @param \Drupal\node\NodeInterface $node
* The node the trail is being built for.
* @param array $context
* Additional context:
* - node: (\Drupal\node\NodeInterface) The node (same as $node).
* - menu: (string|null) The machine name of the site main menu searched,
* or NULL when the node has no resolvable primary site menu.
*
* @see \Drupal\tide_core\TideBreadcrumb::build()
*/
function hook_tide_breadcrumb_alter(array &$trail, NodeInterface $node, array $context) {
// Example: prepend an extra crumb for a specific content type.
if ($node->bundle() === 'news') {
array_splice($trail, 1, 0, [
['title' => 'News', 'url' => '/news'],
]);
}
}
/**
* @} End of "addtogroup hooks".
*/