RouteSubscriber.php in Language Hierarchy 8
File
src/Routing/RouteSubscriber.php
View source
<?php
namespace Drupal\language_hierarchy\Routing;
use Drupal\Core\Routing\RouteSubscriberBase;
use Drupal\config_translation\ConfigMapperManagerInterface;
use Drupal\Core\Routing\RoutingEvents;
use Symfony\Component\Routing\RouteCollection;
class RouteSubscriber extends RouteSubscriberBase {
protected $mapperManager;
public function __construct(ConfigMapperManagerInterface $mapper_manager) {
$this->mapperManager = $mapper_manager;
}
protected function alterRoutes(RouteCollection $collection) {
$mappers = $this->mapperManager
->getMappers($collection);
foreach ($mappers as $mapper) {
$route = $collection
->get($mapper
->getOverviewRouteName());
if ($route
->getDefault('_controller') === '\\Drupal\\config_translation\\Controller\\ConfigTranslationController::itemPage') {
$route
->setDefault('_controller', '\\Drupal\\language_hierarchy\\Controller\\ConfigTranslationController::itemPage');
}
}
}
public static function getSubscribedEvents() {
$events[RoutingEvents::ALTER] = [
'onAlterRoutes',
-110,
];
return $events;
}
}