I have followed this documentation page : https://www.drupal.org/docs/drupal-apis/routing-system/altering-existing-routes-and-adding-new-routes-based-on-dynamic-ones in attempt to alter access of translation overview page ie: www.example.com/node/1/translations
<?php
namespace Drupal\link_enhancements\Routing;
use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
/**
* Listens to the dynamic route events.
*/
class RouteSubscriber extends RouteSubscriberBase {
/**
* {@inheritdoc}
*/
public function alterRoutes(RouteCollection $collection) {
$route_name = "entity.node.content_translation_overview";
var_dump($collection->get($route_name)); exit;
if ($route = $collection->get($route_name)) {
$requirements = $route->getRequirements();
unset($requirements['_permission']);
// if both role then only we will allow ...code will go here.....
$route->setRequirement('_access', 'FALSE');
}
}
}
services:
link_enhancements.route_subscriber:
class: Drupal\link_enhancements\Routing\RouteSubscriber
tags:
- { name: event_subscriber }
But below route output is null and similar code works for other routes but requirement to alter translation overview route which returns null.
$route_name = "entity.node.content_translation_overview";
var_dump($collection->get($route_name)); exit;
core/modules/content_translation/src/Routing/ContentTranslationRouteSubscriber.php
route is added in core module by below code and I have searched and tried but not sure how can we alter such routes, please suggest.
if ($entity_type->hasLinkTemplate('drupal:content-translation-overview')) {
$route = new Route(
$entity_type->getLinkTemplate('drupal:content-translation-overview'),
[
'_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::overview',
'entity_type_id' => $entity_type_id,
],
[
'_entity_access' => $entity_type_id . '.view',
'_access_content_translation_overview' => $entity_type_id,
],
[
'parameters' => [
$entity_type_id => [
'type' => 'entity:' . $entity_type_id,
'load_latest_revision' => $load_latest_revision,
],
],
'_admin_route' => $is_admin,
]
);
$route_name = "entity.$entity_type_id.content_translation_overview";
$collection->add($route_name, $route);
}