Error Route entity.storage.translation_revert does not exist

Created on 20 March 2024, 9 months ago
Updated 11 September 2024, 3 months ago

Problem/Motivation

Symfony\Component\Routing\Exception\RouteNotFoundException: Route "entity.storage.translation_revert" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 206 of core/lib/Drupal/Core/Routing/RouteProvider.php).

Steps to reproduce

When trying to view the revisions of any storage entity with translation, a fatal error is displayed

🐛 Bug report
Status

Fixed

Version

1.3

Component

User interface

Created by

🇨🇦Canada freenjt Vancouver

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @freenjt
  • Issue was unassigned.
  • 🇨🇦Canada freenjt Vancouver
  • 🇨🇦Canada freenjt Vancouver

    Creating a RouteSubscriber service that checks if the route exists, and if it does not exist, adds it, solves the problem.

    class RouteSubscriber extends RouteSubscriberBase {
    
      /**
       * {@inheritdoc}
       */
      protected function alterRoutes(RouteCollection $collection) {
        if (!$this->routeExists('entity.storage.translation_revert')) {
          $this->routes($collection);
        }
      }
    
      /**
       * Function to add the translation_revert route of the Storage entities.
       */
      public function routes(RouteCollection $collection) {
        $entity_type_manager = \Drupal::entityTypeManager();
        $entity_type = $entity_type_manager->getDefinition('storage');
        if ($entity_type->hasLinkTemplate('translation_revert')) {
          $route = new Route($entity_type->getLinkTemplate('translation_revert'));
          $route
            ->setDefaults([
              '_form' => '\Drupal\storage\Form\StorageRevisionRevertTranslationForm',
              '_title' => 'Revert to earlier revision of a translation',
            ])
            ->setRequirement('_permission', 'revert all storage revisions')
            ->setOption('_admin_route', TRUE);
          $entity_type_id = $entity_type->id();
          $collection->add("entity.{$entity_type_id}.translation_revert", $route);
        }
      }
    
      /**
       * Check if rout exists.
       */
      private function routeExists($route_to_check) {
        try {
          \Drupal::service('router.route_provider')
            ->getRouteByName($route_to_check);
        }
        catch (RouteNotFoundException $exception) {
          return FALSE;
        }
        return TRUE;
      }
    
    }
    
  • Status changed to Fixed 9 months ago
  • 🇨🇦Canada freenjt Vancouver
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • 🇨🇦Canada freenjt Vancouver
Production build 0.71.5 2024