Is it possible to add a default controller to the '<front>'
route? There's no default controller defined in system.routing.yml
.
I'm trying to get a handle on it by using the following code:
<?php
namespace Drupal\mymodule\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 front page and set controller.
if ($route = $collection->get('<front>')) {
$route->setDefault('_controller', '\Drupal\mymodule\Controller\MyModuleController::MyModuleMethod');
}
}
}
But it doesn't seem to do anything. However this code works when replacing '<front>'
with another route like help.main
. Why is that? Do I have to add the controller instead of setting it?
(D8)