public function FootermapBlock::buildMenu in footermap: a footer site map 8
Recursively build footer site map.
This method should modify the object variable $mapref.
This deprecates footermap_get_menu().
Parameters
array &$tree: A reference to the menu site tree for a particular menu.
array &$mapref: A reference to the current menu item's children or the root of the map.
Overrides FootermapInterface::buildMenu
1 call to FootermapBlock::buildMenu()
- FootermapBlock::buildMap in src/
Plugin/ Block/ FootermapBlock.php - Build content for footer site map.
File
- src/
Plugin/ Block/ FootermapBlock.php, line 287
Class
- FootermapBlock
- Provide a footer-based site map block based on menu items.
Namespace
Drupal\footermap\Plugin\BlockCode
public function buildMenu(array &$tree, array &$mapref) {
foreach ($tree as $key => $item) {
/** @var \Drupal\Core\Menu\MenuLinkInterface $link */
$link = $item->link;
$link_title = $link
->getTitle();
if ($link
->isEnabled() && !empty($link_title) && !$link instanceof InaccessibleMenuLink) {
// Mapref reference becomes child.
if (isset($mapref['#theme']) && $mapref['#theme'] == 'footermap_header') {
$child =& $mapref['#items'];
}
else {
$child =& $mapref;
}
// Get the menu link entity language, but necessary to load menu link
// content entity which is kind of expensive.
if (strpos($link
->getPluginId(), 'menu_link_content') === 0) {
list(, $uuid) = explode(':', $link
->getPluginId(), 2);
$entity = $this->entityRepository
->loadEntityByUuid('menu_link_content', $uuid);
}
$child['menu-' . $key] = [
'#theme' => 'footermap_item',
'#title' => $link
->getTitle(),
'#url' => $link
->getUrlObject(),
'#attributes' => [
'class' => [
'footermap-item',
'footermap-item--depth-' . $item->depth,
],
],
'#level' => $item->depth,
'#weight' => $link
->getWeight(),
];
}
if ($item->hasChildren) {
$child['menu-' . $key]['#children'] = [];
$child['menu-' . $key]['#attributes']['class'][] = 'footermap-item--haschildren';
$this
->buildMenu($item->subtree, $child['menu-' . $key]['#children']);
}
}
}