protected function MenuTrailByPathActiveTrailHtmlClassTest::buildMenu in Menu Trail By Path 8
Build a menu with the data of $this->menuUrls
Parameters
string $menu_name:
1 call to MenuTrailByPathActiveTrailHtmlClassTest::buildMenu()
- MenuTrailByPathActiveTrailHtmlClassTest::setUp in tests/
src/ Functional/ MenuTrailByPathActiveTrailHtmlClassTest.php
File
- tests/
src/ Functional/ MenuTrailByPathActiveTrailHtmlClassTest.php, line 249
Class
- MenuTrailByPathActiveTrailHtmlClassTest
- Tests that the menu links have the correct css-classes.
Namespace
Drupal\Tests\menu_trail_by_path\FunctionalCode
protected function buildMenu($menu_name = 'main') {
$menu_handler = \Drupal::service('plugin.manager.menu.link');
$menu_handler
->deleteLinksInMenu($menu_name);
$menu_links = [];
$menu_link_weight = -30;
foreach ($this->menuUrls as $title => $url) {
$titles = explode(' » ', $title);
$title_short = array_pop($titles);
$parent = $titles ? $menu_links[implode(' » ', $titles)]
->getPluginId() : NULL;
$menu_links[$title] = MenuLinkContent::create([
'menu_name' => $menu_name,
'title' => $title_short,
'link' => [
'uri' => $url
->toUriString(),
],
'parent' => $parent,
'expanded' => TRUE,
'weight' => $menu_link_weight,
]);
$menu_links[$title]
->save();
$menu_link_weight++;
}
}