Drupal 8 has a new menu system, there is no hook_menu
and no hook_menu_alter
anymore.
If you want to alter an existing route, it is a little bit more complicated in comparison to Drupal 7.
In your module you have to create a class file at YOURMODULE/src/Routing/CLASSNAME.php
that extends RouteSubscriberBase
:
/**
* @file
* Contains \Drupal\YOURMODULE\Routing\RouteSubscriber.
*/
namespace Drupal\YOURMODULE\Routing;
use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;
/**
* Listens to the dynamic route events.
*/
class RouteSubscriber extends RouteSubscriberBase {
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
// Get the route you want to alter
$route = $collection->get('system.admin_content');
// alter the route...
}
}
You can take the RouteSubsciber class of the node module as an example.
To let your RouteSubscriber be recognized you also have to create a YOURMODULE.services.yml
file in the root of your modules directory:
services:
node.route_subscriber:
class: Drupal\YOURMODULE\Routing\RouteSubscriber
tags:
- { name: event_subscriber }
To get a better insight to the new menu system I would recommend the following articles:
Edit:
As mentioned by Berdir, the menu system has a different structure now, which has nothing to do with D7's menu system, so there is no such thing as a menu type anymore.