comparison core/modules/content_translation/src/Routing/ContentTranslationRouteSubscriber.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children 129ea1e6d783
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php 1 <?php
2 2
3 namespace Drupal\content_translation\Routing; 3 namespace Drupal\content_translation\Routing;
4 4
5 use Drupal\content_translation\ContentTranslationManager;
5 use Drupal\content_translation\ContentTranslationManagerInterface; 6 use Drupal\content_translation\ContentTranslationManagerInterface;
6 use Drupal\Core\Routing\RouteSubscriberBase; 7 use Drupal\Core\Routing\RouteSubscriberBase;
7 use Drupal\Core\Routing\RoutingEvents; 8 use Drupal\Core\Routing\RoutingEvents;
8 use Symfony\Component\Routing\Route; 9 use Symfony\Component\Routing\Route;
9 use Symfony\Component\Routing\RouteCollection; 10 use Symfony\Component\Routing\RouteCollection;
53 if ($edit_route = $collection->get($route_name)) { 54 if ($edit_route = $collection->get($route_name)) {
54 $is_admin = (bool) $edit_route->getOption('_admin_route'); 55 $is_admin = (bool) $edit_route->getOption('_admin_route');
55 } 56 }
56 57
57 $path = $base_path . '/translations'; 58 $path = $base_path . '/translations';
59 $load_latest_revision = ContentTranslationManager::isPendingRevisionSupportEnabled($entity_type_id);
58 60
59 $route = new Route( 61 $route = new Route(
60 $path, 62 $path,
61 [ 63 [
62 '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::overview', 64 '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::overview',
68 ], 70 ],
69 [ 71 [
70 'parameters' => [ 72 'parameters' => [
71 $entity_type_id => [ 73 $entity_type_id => [
72 'type' => 'entity:' . $entity_type_id, 74 'type' => 'entity:' . $entity_type_id,
75 'load_latest_revision' => $load_latest_revision,
73 ], 76 ],
74 ], 77 ],
75 '_admin_route' => $is_admin, 78 '_admin_route' => $is_admin,
76 ] 79 ]
77 ); 80 );
100 'target' => [ 103 'target' => [
101 'type' => 'language', 104 'type' => 'language',
102 ], 105 ],
103 $entity_type_id => [ 106 $entity_type_id => [
104 'type' => 'entity:' . $entity_type_id, 107 'type' => 'entity:' . $entity_type_id,
108 'load_latest_revision' => $load_latest_revision,
105 ], 109 ],
106 ], 110 ],
107 '_admin_route' => $is_admin, 111 '_admin_route' => $is_admin,
108 ] 112 ]
109 ); 113 );
125 'language' => [ 129 'language' => [
126 'type' => 'language', 130 'type' => 'language',
127 ], 131 ],
128 $entity_type_id => [ 132 $entity_type_id => [
129 'type' => 'entity:' . $entity_type_id, 133 'type' => 'entity:' . $entity_type_id,
134 'load_latest_revision' => $load_latest_revision,
130 ], 135 ],
131 ], 136 ],
132 '_admin_route' => $is_admin, 137 '_admin_route' => $is_admin,
133 ] 138 ]
134 ); 139 );
150 'language' => [ 155 'language' => [
151 'type' => 'language', 156 'type' => 'language',
152 ], 157 ],
153 $entity_type_id => [ 158 $entity_type_id => [
154 'type' => 'entity:' . $entity_type_id, 159 'type' => 'entity:' . $entity_type_id,
160 'load_latest_revision' => $load_latest_revision,
155 ], 161 ],
156 ], 162 ],
157 '_admin_route' => $is_admin, 163 '_admin_route' => $is_admin,
158 ] 164 ]
159 ); 165 );
160 $collection->add("entity.$entity_type_id.content_translation_delete", $route); 166 $collection->add("entity.$entity_type_id.content_translation_delete", $route);
167
168 // Add our custom translation deletion access checker.
169 if ($load_latest_revision) {
170 $entity_delete_route = $collection->get("entity.$entity_type_id.delete_form");
171 if ($entity_delete_route) {
172 $entity_delete_route->addRequirements(['_access_content_translation_delete' => "$entity_type_id.delete"]);
173 }
174 }
161 } 175 }
162 } 176 }
163 177
164 /** 178 /**
165 * {@inheritdoc} 179 * {@inheritdoc}