I want to create a block that contains somes links of a menu, without using the interface. So I created a custom module. Inside, there are somes files.
a mymodule/test.links.menu.yml :
test.menu.listown:
title: list
route_name: test.listown
test.menu.addnew:
title: Add new
route_name: test.addnew
weight: 0
parent: test.menu.listown
and a mymodule/src/Plugin/Block/test_block_main.php
class test_block_main extends BlockBase {
public function build(){
$mp = \Drupal::menuTree()->getCurrentRouteMenuTreeParameters("test.menu.listown");
$test = \Drupal::menuTree()->load("test.menu.listown", $mp);
$render = \Drupal::menuTree()->build($test);
return array('#markup' => \Drupal::service('renderer')->render($render));
}
}
I cleared caches (drush cache-rebuild
). When I go to my homepage, the "test_block_main" is displayed, but it is empty. Why is my custom block empty? Is the "test.menu.listown"
parameter passed to the methods not correct?