protected ContentTranslationRouteSubscriber::alterRoutes(RouteCollection $collection)
Alters existing routes for a specific collection.
Parameters
\Symfony\Component\Routing\RouteCollection $collection: The route collection for adding routes.
Overrides RouteSubscriberBase::alterRoutes
File
- core/modules/content_translation/src/Routing/ContentTranslationRouteSubscriber.php, line 36
Class
- ContentTranslationRouteSubscriber
- Subscriber for entity translation routes.
Namespace
Drupal\content_translation\Routing
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | protected function alterRoutes(RouteCollection $collection ) { foreach ( $this ->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type ) { // Try to get the route from the current collection. $link_template = $entity_type ->getLinkTemplate( 'canonical' ); if ( strpos ( $link_template , '/' ) !== FALSE) { $base_path = '/' . $link_template ; } else { if (! $entity_route = $collection ->get( "entity.$entity_type_id.canonical" )) { continue ; } $base_path = $entity_route ->getPath(); } // Inherit admin route status from edit route, if exists. $is_admin = FALSE; $route_name = "entity.$entity_type_id.edit_form" ; if ( $edit_route = $collection ->get( $route_name )) { $is_admin = (bool) $edit_route ->getOption( '_admin_route' ); } $path = $base_path . '/translations' ; $route = new Route( $path , array ( '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::overview' , 'entity_type_id' => $entity_type_id , ), array ( '_entity_access' => $entity_type_id . '.view' , '_access_content_translation_overview' => $entity_type_id , ), array ( 'parameters' => array ( $entity_type_id => array ( 'type' => 'entity:' . $entity_type_id , ), ), '_admin_route' => $is_admin , ) ); $route_name = "entity.$entity_type_id.content_translation_overview" ; $collection ->add( $route_name , $route ); $route = new Route( $path . '/add/{source}/{target}' , array ( '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::add' , 'source' => NULL, 'target' => NULL, '_title' => 'Add' , 'entity_type_id' => $entity_type_id , ), array ( '_entity_access' => $entity_type_id . '.view' , '_access_content_translation_manage' => 'create' , ), array ( 'parameters' => array ( 'source' => array ( 'type' => 'language' , ), 'target' => array ( 'type' => 'language' , ), $entity_type_id => array ( 'type' => 'entity:' . $entity_type_id , ), ), '_admin_route' => $is_admin , ) ); $collection ->add( "entity.$entity_type_id.content_translation_add" , $route ); $route = new Route( $path . '/edit/{language}' , array ( '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::edit' , 'language' => NULL, '_title' => 'Edit' , 'entity_type_id' => $entity_type_id , ), array ( '_access_content_translation_manage' => 'update' , ), array ( 'parameters' => array ( 'language' => array ( 'type' => 'language' , ), $entity_type_id => array ( 'type' => 'entity:' . $entity_type_id , ), ), '_admin_route' => $is_admin , ) ); $collection ->add( "entity.$entity_type_id.content_translation_edit" , $route ); $route = new Route( $path . '/delete/{language}' , array ( '_entity_form' => $entity_type_id . '.content_translation_deletion' , 'language' => NULL, '_title' => 'Delete' , 'entity_type_id' => $entity_type_id , ), array ( '_access_content_translation_manage' => 'delete' , ), array ( 'parameters' => array ( 'language' => array ( 'type' => 'language' , ), $entity_type_id => array ( 'type' => 'entity:' . $entity_type_id , ), ), '_admin_route' => $is_admin , ) ); $collection ->add( "entity.$entity_type_id.content_translation_delete" , $route ); } } |
Please login to continue.