Chris@0: contentTranslationManager = $content_translation_manager; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function alterRoutes(RouteCollection $collection) { Chris@0: foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) { Chris@0: // Inherit admin route status from edit route, if exists. Chris@0: $is_admin = FALSE; Chris@0: $route_name = "entity.$entity_type_id.edit_form"; Chris@0: if ($edit_route = $collection->get($route_name)) { Chris@0: $is_admin = (bool) $edit_route->getOption('_admin_route'); Chris@0: } Chris@0: Chris@14: $load_latest_revision = ContentTranslationManager::isPendingRevisionSupportEnabled($entity_type_id); Chris@0: Chris@17: if ($entity_type->hasLinkTemplate('drupal:content-translation-overview')) { Chris@17: $route = new Route( Chris@17: $entity_type->getLinkTemplate('drupal:content-translation-overview'), Chris@17: [ Chris@17: '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::overview', Chris@17: 'entity_type_id' => $entity_type_id, Chris@17: ], Chris@17: [ Chris@17: '_entity_access' => $entity_type_id . '.view', Chris@17: '_access_content_translation_overview' => $entity_type_id, Chris@17: ], Chris@17: [ Chris@17: 'parameters' => [ Chris@17: $entity_type_id => [ Chris@17: 'type' => 'entity:' . $entity_type_id, Chris@17: 'load_latest_revision' => $load_latest_revision, Chris@17: ], Chris@0: ], Chris@17: '_admin_route' => $is_admin, Chris@17: ] Chris@17: ); Chris@17: $route_name = "entity.$entity_type_id.content_translation_overview"; Chris@17: $collection->add($route_name, $route); Chris@17: } Chris@17: Chris@17: if ($entity_type->hasLinkTemplate('drupal:content-translation-add')) { Chris@17: $route = new Route( Chris@17: $entity_type->getLinkTemplate('drupal:content-translation-add'), Chris@17: [ Chris@17: '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::add', Chris@17: 'source' => NULL, Chris@17: 'target' => NULL, Chris@17: '_title' => 'Add', Chris@17: 'entity_type_id' => $entity_type_id, Chris@17: Chris@0: ], Chris@17: [ Chris@17: '_entity_access' => $entity_type_id . '.view', Chris@17: '_access_content_translation_manage' => 'create', Chris@17: ], Chris@17: [ Chris@17: 'parameters' => [ Chris@17: 'source' => [ Chris@17: 'type' => 'language', Chris@17: ], Chris@17: 'target' => [ Chris@17: 'type' => 'language', Chris@17: ], Chris@17: $entity_type_id => [ Chris@17: 'type' => 'entity:' . $entity_type_id, Chris@17: 'load_latest_revision' => $load_latest_revision, Chris@17: ], Chris@17: ], Chris@17: '_admin_route' => $is_admin, Chris@17: ] Chris@17: ); Chris@17: $collection->add("entity.$entity_type_id.content_translation_add", $route); Chris@17: } Chris@0: Chris@17: if ($entity_type->hasLinkTemplate('drupal:content-translation-edit')) { Chris@17: $route = new Route( Chris@17: $entity_type->getLinkTemplate('drupal:content-translation-edit'), Chris@17: [ Chris@17: '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::edit', Chris@17: 'language' => NULL, Chris@17: '_title' => 'Edit', Chris@17: 'entity_type_id' => $entity_type_id, Chris@17: ], Chris@17: [ Chris@17: '_access_content_translation_manage' => 'update', Chris@17: ], Chris@17: [ Chris@17: 'parameters' => [ Chris@17: 'language' => [ Chris@17: 'type' => 'language', Chris@17: ], Chris@17: $entity_type_id => [ Chris@17: 'type' => 'entity:' . $entity_type_id, Chris@17: 'load_latest_revision' => $load_latest_revision, Chris@17: ], Chris@17: ], Chris@17: '_admin_route' => $is_admin, Chris@17: ] Chris@17: ); Chris@17: $collection->add("entity.$entity_type_id.content_translation_edit", $route); Chris@17: } Chris@0: Chris@17: if ($entity_type->hasLinkTemplate('drupal:content-translation-delete')) { Chris@17: $route = new Route( Chris@17: $entity_type->getLinkTemplate('drupal:content-translation-delete'), Chris@17: [ Chris@17: '_entity_form' => $entity_type_id . '.content_translation_deletion', Chris@17: 'language' => NULL, Chris@17: '_title' => 'Delete', Chris@17: 'entity_type_id' => $entity_type_id, Chris@17: ], Chris@17: [ Chris@17: '_access_content_translation_manage' => 'delete', Chris@17: ], Chris@17: [ Chris@17: 'parameters' => [ Chris@17: 'language' => [ Chris@17: 'type' => 'language', Chris@17: ], Chris@17: $entity_type_id => [ Chris@17: 'type' => 'entity:' . $entity_type_id, Chris@17: 'load_latest_revision' => $load_latest_revision, Chris@17: ], Chris@0: ], Chris@17: '_admin_route' => $is_admin, Chris@17: ] Chris@17: ); Chris@17: $collection->add("entity.$entity_type_id.content_translation_delete", $route); Chris@17: } Chris@14: Chris@14: // Add our custom translation deletion access checker. Chris@14: if ($load_latest_revision) { Chris@14: $entity_delete_route = $collection->get("entity.$entity_type_id.delete_form"); Chris@14: if ($entity_delete_route) { Chris@14: $entity_delete_route->addRequirements(['_access_content_translation_delete' => "$entity_type_id.delete"]); Chris@14: } Chris@14: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function getSubscribedEvents() { Chris@0: $events = parent::getSubscribedEvents(); Chris@0: // Should run after AdminRouteSubscriber so the routes can inherit admin Chris@0: // status of the edit routes on entities. Therefore priority -210. Chris@0: $events[RoutingEvents::ALTER] = ['onAlterRoutes', -210]; Chris@0: return $events; Chris@0: } Chris@0: Chris@0: }