Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / content_translation / src / Routing / ContentTranslationRouteSubscriber.php
index fa1ac3bbf902a582ef2c2f40c2d3b5ef42ba3575..6cd3b350dfe80009660fc218409b9e638e5d4a0a 100644 (file)
@@ -36,18 +36,6 @@ class ContentTranslationRouteSubscriber extends RouteSubscriberBase {
    */
   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";
@@ -55,115 +43,122 @@ class ContentTranslationRouteSubscriber extends RouteSubscriberBase {
         $is_admin = (bool) $edit_route->getOption('_admin_route');
       }
 
-      $path = $base_path . '/translations';
       $load_latest_revision = ContentTranslationManager::isPendingRevisionSupportEnabled($entity_type_id);
 
-      $route = new Route(
-        $path,
-        [
-          '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::overview',
-          'entity_type_id' => $entity_type_id,
-        ],
-        [
-          '_entity_access' => $entity_type_id . '.view',
-          '_access_content_translation_overview' => $entity_type_id,
-        ],
-        [
-          'parameters' => [
-            $entity_type_id => [
-              'type' => 'entity:' . $entity_type_id,
-              'load_latest_revision' => $load_latest_revision,
-            ],
+      if ($entity_type->hasLinkTemplate('drupal:content-translation-overview')) {
+        $route = new Route(
+          $entity_type->getLinkTemplate('drupal:content-translation-overview'),
+          [
+            '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::overview',
+            'entity_type_id' => $entity_type_id,
+          ],
+          [
+            '_entity_access' => $entity_type_id . '.view',
+            '_access_content_translation_overview' => $entity_type_id,
           ],
-          '_admin_route' => $is_admin,
-        ]
-      );
-      $route_name = "entity.$entity_type_id.content_translation_overview";
-      $collection->add($route_name, $route);
+          [
+            'parameters' => [
+              $entity_type_id => [
+                'type' => 'entity:' . $entity_type_id,
+                'load_latest_revision' => $load_latest_revision,
+              ],
+            ],
+            '_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}',
-        [
-          '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::add',
-          'source' => NULL,
-          'target' => NULL,
-          '_title' => 'Add',
-          'entity_type_id' => $entity_type_id,
+      if ($entity_type->hasLinkTemplate('drupal:content-translation-add')) {
+        $route = new Route(
+          $entity_type->getLinkTemplate('drupal:content-translation-add'),
+          [
+            '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::add',
+            'source' => NULL,
+            'target' => NULL,
+            '_title' => 'Add',
+            'entity_type_id' => $entity_type_id,
 
-        ],
-        [
-          '_entity_access' => $entity_type_id . '.view',
-          '_access_content_translation_manage' => 'create',
-        ],
-        [
-          'parameters' => [
-            'source' => [
-              'type' => 'language',
-            ],
-            'target' => [
-              'type' => 'language',
-            ],
-            $entity_type_id => [
-              'type' => 'entity:' . $entity_type_id,
-              'load_latest_revision' => $load_latest_revision,
-            ],
           ],
-          '_admin_route' => $is_admin,
-        ]
-      );
-      $collection->add("entity.$entity_type_id.content_translation_add", $route);
-
-      $route = new Route(
-        $path . '/edit/{language}',
-        [
-          '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::edit',
-          'language' => NULL,
-          '_title' => 'Edit',
-          'entity_type_id' => $entity_type_id,
-        ],
-        [
-          '_access_content_translation_manage' => 'update',
-        ],
-        [
-          'parameters' => [
-            'language' => [
-              'type' => 'language',
-            ],
-            $entity_type_id => [
-              'type' => 'entity:' . $entity_type_id,
-              'load_latest_revision' => $load_latest_revision,
-            ],
+          [
+            '_entity_access' => $entity_type_id . '.view',
+            '_access_content_translation_manage' => 'create',
           ],
-          '_admin_route' => $is_admin,
-        ]
-      );
-      $collection->add("entity.$entity_type_id.content_translation_edit", $route);
-
-      $route = new Route(
-        $path . '/delete/{language}',
-        [
-          '_entity_form' => $entity_type_id . '.content_translation_deletion',
-          'language' => NULL,
-          '_title' => 'Delete',
-          'entity_type_id' => $entity_type_id,
-        ],
-        [
-          '_access_content_translation_manage' => 'delete',
-        ],
-        [
-          'parameters' => [
-            'language' => [
-              'type' => 'language',
+          [
+            'parameters' => [
+              'source' => [
+                'type' => 'language',
+              ],
+              'target' => [
+                'type' => 'language',
+              ],
+              $entity_type_id => [
+                'type' => 'entity:' . $entity_type_id,
+                'load_latest_revision' => $load_latest_revision,
+              ],
             ],
-            $entity_type_id => [
-              'type' => 'entity:' . $entity_type_id,
-              'load_latest_revision' => $load_latest_revision,
+            '_admin_route' => $is_admin,
+          ]
+        );
+        $collection->add("entity.$entity_type_id.content_translation_add", $route);
+      }
+
+      if ($entity_type->hasLinkTemplate('drupal:content-translation-edit')) {
+        $route = new Route(
+          $entity_type->getLinkTemplate('drupal:content-translation-edit'),
+          [
+            '_controller' => '\Drupal\content_translation\Controller\ContentTranslationController::edit',
+            'language' => NULL,
+            '_title' => 'Edit',
+            'entity_type_id' => $entity_type_id,
+          ],
+          [
+            '_access_content_translation_manage' => 'update',
+          ],
+          [
+            'parameters' => [
+              'language' => [
+                'type' => 'language',
+              ],
+              $entity_type_id => [
+                'type' => 'entity:' . $entity_type_id,
+                'load_latest_revision' => $load_latest_revision,
+              ],
             ],
+            '_admin_route' => $is_admin,
+          ]
+        );
+        $collection->add("entity.$entity_type_id.content_translation_edit", $route);
+      }
+
+      if ($entity_type->hasLinkTemplate('drupal:content-translation-delete')) {
+        $route = new Route(
+          $entity_type->getLinkTemplate('drupal:content-translation-delete'),
+          [
+            '_entity_form' => $entity_type_id . '.content_translation_deletion',
+            'language' => NULL,
+            '_title' => 'Delete',
+            'entity_type_id' => $entity_type_id,
           ],
-          '_admin_route' => $is_admin,
-        ]
-      );
-      $collection->add("entity.$entity_type_id.content_translation_delete", $route);
+          [
+            '_access_content_translation_manage' => 'delete',
+          ],
+          [
+            'parameters' => [
+              'language' => [
+                'type' => 'language',
+              ],
+              $entity_type_id => [
+                'type' => 'entity:' . $entity_type_id,
+                'load_latest_revision' => $load_latest_revision,
+              ],
+            ],
+            '_admin_route' => $is_admin,
+          ]
+        );
+        $collection->add("entity.$entity_type_id.content_translation_delete", $route);
+      }
 
       // Add our custom translation deletion access checker.
       if ($load_latest_revision) {