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: // Try to get the route from the current collection. Chris@0: $link_template = $entity_type->getLinkTemplate('canonical'); Chris@0: if (strpos($link_template, '/') !== FALSE) { Chris@0: $base_path = '/' . $link_template; Chris@0: } Chris@0: else { Chris@0: if (!$entity_route = $collection->get("entity.$entity_type_id.canonical")) { Chris@0: continue; Chris@0: } Chris@0: $base_path = $entity_route->getPath(); Chris@0: } Chris@0: 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@0: $path = $base_path . '/translations'; Chris@0: Chris@0: $route = new Route( Chris@0: $path, Chris@0: [ Chris@0: '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::overview', Chris@0: 'entity_type_id' => $entity_type_id, Chris@0: ], Chris@0: [ Chris@0: '_entity_access' => $entity_type_id . '.view', Chris@0: '_access_content_translation_overview' => $entity_type_id, Chris@0: ], Chris@0: [ Chris@0: 'parameters' => [ Chris@0: $entity_type_id => [ Chris@0: 'type' => 'entity:' . $entity_type_id, Chris@0: ], Chris@0: ], Chris@0: '_admin_route' => $is_admin, Chris@0: ] Chris@0: ); Chris@0: $route_name = "entity.$entity_type_id.content_translation_overview"; Chris@0: $collection->add($route_name, $route); Chris@0: Chris@0: $route = new Route( Chris@0: $path . '/add/{source}/{target}', Chris@0: [ Chris@0: '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::add', Chris@0: 'source' => NULL, Chris@0: 'target' => NULL, Chris@0: '_title' => 'Add', Chris@0: 'entity_type_id' => $entity_type_id, Chris@0: Chris@0: ], Chris@0: [ Chris@0: '_entity_access' => $entity_type_id . '.view', Chris@0: '_access_content_translation_manage' => 'create', Chris@0: ], Chris@0: [ Chris@0: 'parameters' => [ Chris@0: 'source' => [ Chris@0: 'type' => 'language', Chris@0: ], Chris@0: 'target' => [ Chris@0: 'type' => 'language', Chris@0: ], Chris@0: $entity_type_id => [ Chris@0: 'type' => 'entity:' . $entity_type_id, Chris@0: ], Chris@0: ], Chris@0: '_admin_route' => $is_admin, Chris@0: ] Chris@0: ); Chris@0: $collection->add("entity.$entity_type_id.content_translation_add", $route); Chris@0: Chris@0: $route = new Route( Chris@0: $path . '/edit/{language}', Chris@0: [ Chris@0: '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::edit', Chris@0: 'language' => NULL, Chris@0: '_title' => 'Edit', Chris@0: 'entity_type_id' => $entity_type_id, Chris@0: ], Chris@0: [ Chris@0: '_access_content_translation_manage' => 'update', Chris@0: ], Chris@0: [ Chris@0: 'parameters' => [ Chris@0: 'language' => [ Chris@0: 'type' => 'language', Chris@0: ], Chris@0: $entity_type_id => [ Chris@0: 'type' => 'entity:' . $entity_type_id, Chris@0: ], Chris@0: ], Chris@0: '_admin_route' => $is_admin, Chris@0: ] Chris@0: ); Chris@0: $collection->add("entity.$entity_type_id.content_translation_edit", $route); Chris@0: Chris@0: $route = new Route( Chris@0: $path . '/delete/{language}', Chris@0: [ Chris@0: '_entity_form' => $entity_type_id . '.content_translation_deletion', Chris@0: 'language' => NULL, Chris@0: '_title' => 'Delete', Chris@0: 'entity_type_id' => $entity_type_id, Chris@0: ], Chris@0: [ Chris@0: '_access_content_translation_manage' => 'delete', Chris@0: ], Chris@0: [ Chris@0: 'parameters' => [ Chris@0: 'language' => [ Chris@0: 'type' => 'language', Chris@0: ], Chris@0: $entity_type_id => [ Chris@0: 'type' => 'entity:' . $entity_type_id, Chris@0: ], Chris@0: ], Chris@0: '_admin_route' => $is_admin, Chris@0: ] Chris@0: ); Chris@0: $collection->add("entity.$entity_type_id.content_translation_delete", $route); 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: }