Mercurial > hg > isophonics-drupal-site
comparison core/modules/content_translation/src/Routing/ContentTranslationRouteSubscriber.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
34 /** | 34 /** |
35 * {@inheritdoc} | 35 * {@inheritdoc} |
36 */ | 36 */ |
37 protected function alterRoutes(RouteCollection $collection) { | 37 protected function alterRoutes(RouteCollection $collection) { |
38 foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) { | 38 foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) { |
39 // Try to get the route from the current collection. | |
40 $link_template = $entity_type->getLinkTemplate('canonical'); | |
41 if (strpos($link_template, '/') !== FALSE) { | |
42 $base_path = '/' . $link_template; | |
43 } | |
44 else { | |
45 if (!$entity_route = $collection->get("entity.$entity_type_id.canonical")) { | |
46 continue; | |
47 } | |
48 $base_path = $entity_route->getPath(); | |
49 } | |
50 | |
51 // Inherit admin route status from edit route, if exists. | 39 // Inherit admin route status from edit route, if exists. |
52 $is_admin = FALSE; | 40 $is_admin = FALSE; |
53 $route_name = "entity.$entity_type_id.edit_form"; | 41 $route_name = "entity.$entity_type_id.edit_form"; |
54 if ($edit_route = $collection->get($route_name)) { | 42 if ($edit_route = $collection->get($route_name)) { |
55 $is_admin = (bool) $edit_route->getOption('_admin_route'); | 43 $is_admin = (bool) $edit_route->getOption('_admin_route'); |
56 } | 44 } |
57 | 45 |
58 $path = $base_path . '/translations'; | |
59 $load_latest_revision = ContentTranslationManager::isPendingRevisionSupportEnabled($entity_type_id); | 46 $load_latest_revision = ContentTranslationManager::isPendingRevisionSupportEnabled($entity_type_id); |
60 | 47 |
61 $route = new Route( | 48 if ($entity_type->hasLinkTemplate('drupal:content-translation-overview')) { |
62 $path, | 49 $route = new Route( |
63 [ | 50 $entity_type->getLinkTemplate('drupal:content-translation-overview'), |
64 '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::overview', | 51 [ |
65 'entity_type_id' => $entity_type_id, | 52 '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::overview', |
66 ], | 53 'entity_type_id' => $entity_type_id, |
67 [ | 54 ], |
68 '_entity_access' => $entity_type_id . '.view', | 55 [ |
69 '_access_content_translation_overview' => $entity_type_id, | 56 '_entity_access' => $entity_type_id . '.view', |
70 ], | 57 '_access_content_translation_overview' => $entity_type_id, |
71 [ | 58 ], |
72 'parameters' => [ | 59 [ |
73 $entity_type_id => [ | 60 'parameters' => [ |
74 'type' => 'entity:' . $entity_type_id, | 61 $entity_type_id => [ |
75 'load_latest_revision' => $load_latest_revision, | 62 'type' => 'entity:' . $entity_type_id, |
63 'load_latest_revision' => $load_latest_revision, | |
64 ], | |
76 ], | 65 ], |
66 '_admin_route' => $is_admin, | |
67 ] | |
68 ); | |
69 $route_name = "entity.$entity_type_id.content_translation_overview"; | |
70 $collection->add($route_name, $route); | |
71 } | |
72 | |
73 if ($entity_type->hasLinkTemplate('drupal:content-translation-add')) { | |
74 $route = new Route( | |
75 $entity_type->getLinkTemplate('drupal:content-translation-add'), | |
76 [ | |
77 '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::add', | |
78 'source' => NULL, | |
79 'target' => NULL, | |
80 '_title' => 'Add', | |
81 'entity_type_id' => $entity_type_id, | |
82 | |
77 ], | 83 ], |
78 '_admin_route' => $is_admin, | 84 [ |
79 ] | 85 '_entity_access' => $entity_type_id . '.view', |
80 ); | 86 '_access_content_translation_manage' => 'create', |
81 $route_name = "entity.$entity_type_id.content_translation_overview"; | 87 ], |
82 $collection->add($route_name, $route); | 88 [ |
89 'parameters' => [ | |
90 'source' => [ | |
91 'type' => 'language', | |
92 ], | |
93 'target' => [ | |
94 'type' => 'language', | |
95 ], | |
96 $entity_type_id => [ | |
97 'type' => 'entity:' . $entity_type_id, | |
98 'load_latest_revision' => $load_latest_revision, | |
99 ], | |
100 ], | |
101 '_admin_route' => $is_admin, | |
102 ] | |
103 ); | |
104 $collection->add("entity.$entity_type_id.content_translation_add", $route); | |
105 } | |
83 | 106 |
84 $route = new Route( | 107 if ($entity_type->hasLinkTemplate('drupal:content-translation-edit')) { |
85 $path . '/add/{source}/{target}', | 108 $route = new Route( |
86 [ | 109 $entity_type->getLinkTemplate('drupal:content-translation-edit'), |
87 '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::add', | 110 [ |
88 'source' => NULL, | 111 '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::edit', |
89 'target' => NULL, | 112 'language' => NULL, |
90 '_title' => 'Add', | 113 '_title' => 'Edit', |
91 'entity_type_id' => $entity_type_id, | 114 'entity_type_id' => $entity_type_id, |
115 ], | |
116 [ | |
117 '_access_content_translation_manage' => 'update', | |
118 ], | |
119 [ | |
120 'parameters' => [ | |
121 'language' => [ | |
122 'type' => 'language', | |
123 ], | |
124 $entity_type_id => [ | |
125 'type' => 'entity:' . $entity_type_id, | |
126 'load_latest_revision' => $load_latest_revision, | |
127 ], | |
128 ], | |
129 '_admin_route' => $is_admin, | |
130 ] | |
131 ); | |
132 $collection->add("entity.$entity_type_id.content_translation_edit", $route); | |
133 } | |
92 | 134 |
93 ], | 135 if ($entity_type->hasLinkTemplate('drupal:content-translation-delete')) { |
94 [ | 136 $route = new Route( |
95 '_entity_access' => $entity_type_id . '.view', | 137 $entity_type->getLinkTemplate('drupal:content-translation-delete'), |
96 '_access_content_translation_manage' => 'create', | 138 [ |
97 ], | 139 '_entity_form' => $entity_type_id . '.content_translation_deletion', |
98 [ | 140 'language' => NULL, |
99 'parameters' => [ | 141 '_title' => 'Delete', |
100 'source' => [ | 142 'entity_type_id' => $entity_type_id, |
101 'type' => 'language', | 143 ], |
144 [ | |
145 '_access_content_translation_manage' => 'delete', | |
146 ], | |
147 [ | |
148 'parameters' => [ | |
149 'language' => [ | |
150 'type' => 'language', | |
151 ], | |
152 $entity_type_id => [ | |
153 'type' => 'entity:' . $entity_type_id, | |
154 'load_latest_revision' => $load_latest_revision, | |
155 ], | |
102 ], | 156 ], |
103 'target' => [ | 157 '_admin_route' => $is_admin, |
104 'type' => 'language', | 158 ] |
105 ], | 159 ); |
106 $entity_type_id => [ | 160 $collection->add("entity.$entity_type_id.content_translation_delete", $route); |
107 'type' => 'entity:' . $entity_type_id, | 161 } |
108 'load_latest_revision' => $load_latest_revision, | |
109 ], | |
110 ], | |
111 '_admin_route' => $is_admin, | |
112 ] | |
113 ); | |
114 $collection->add("entity.$entity_type_id.content_translation_add", $route); | |
115 | |
116 $route = new Route( | |
117 $path . '/edit/{language}', | |
118 [ | |
119 '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::edit', | |
120 'language' => NULL, | |
121 '_title' => 'Edit', | |
122 'entity_type_id' => $entity_type_id, | |
123 ], | |
124 [ | |
125 '_access_content_translation_manage' => 'update', | |
126 ], | |
127 [ | |
128 'parameters' => [ | |
129 'language' => [ | |
130 'type' => 'language', | |
131 ], | |
132 $entity_type_id => [ | |
133 'type' => 'entity:' . $entity_type_id, | |
134 'load_latest_revision' => $load_latest_revision, | |
135 ], | |
136 ], | |
137 '_admin_route' => $is_admin, | |
138 ] | |
139 ); | |
140 $collection->add("entity.$entity_type_id.content_translation_edit", $route); | |
141 | |
142 $route = new Route( | |
143 $path . '/delete/{language}', | |
144 [ | |
145 '_entity_form' => $entity_type_id . '.content_translation_deletion', | |
146 'language' => NULL, | |
147 '_title' => 'Delete', | |
148 'entity_type_id' => $entity_type_id, | |
149 ], | |
150 [ | |
151 '_access_content_translation_manage' => 'delete', | |
152 ], | |
153 [ | |
154 'parameters' => [ | |
155 'language' => [ | |
156 'type' => 'language', | |
157 ], | |
158 $entity_type_id => [ | |
159 'type' => 'entity:' . $entity_type_id, | |
160 'load_latest_revision' => $load_latest_revision, | |
161 ], | |
162 ], | |
163 '_admin_route' => $is_admin, | |
164 ] | |
165 ); | |
166 $collection->add("entity.$entity_type_id.content_translation_delete", $route); | |
167 | 162 |
168 // Add our custom translation deletion access checker. | 163 // Add our custom translation deletion access checker. |
169 if ($load_latest_revision) { | 164 if ($load_latest_revision) { |
170 $entity_delete_route = $collection->get("entity.$entity_type_id.delete_form"); | 165 $entity_delete_route = $collection->get("entity.$entity_type_id.delete_form"); |
171 if ($entity_delete_route) { | 166 if ($entity_delete_route) { |