Updating from 1.0 to 1.1 breaks all routes on nodes with a workflow attached (and probably terms as well?) giving a wsod on viewing. Error is Symfony\Component\Routing\Exception\RouteNotFoundException: Route "entity.node.workflow_history" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 202 of core/lib/Drupal/Core/Routing/RouteProvider.php).

This is likely due to the commit here https://www.drupal.org/project/workflow/issues/2584953#comment-12570162

Looking into how this might be fixed. Am guessing routes need to be changed in the router table

CommentFileSizeAuthor
#6 2969569-6.patch752 bytesel1_1el

Comments

el1_1el created an issue. See original summary.

johnv’s picture

Does flushing the caches help?

el1_1el’s picture

No. I also tried rebuilding routes. Then I got distracted with an unrelated issue and couldn't debug further. Reverting to 1.0 "fixes" the problem. I'll post back when I know more.

el1_1el’s picture

In src/Plugin/Derivative/WorkflowLocalTask.php in the method getDerivativeDefinitions, if I loop through $fields and add the field name ($fields[$key]) to the route_name it works again.
ex

  public function getDerivativeDefinitions($base_plugin_definition) {
    $this->derivatives = [];

    $field_list = workflow_get_workflow_fields_by_entity_type();
    foreach ($field_list as $entity_type_id => $fields) {
      foreach ($fields as $fieldname => $field) {
        $this->derivatives["entity.$entity_type_id.workflow_history"] = [
          'route_name' => "entity.$entity_type_id.workflow_history.$fieldname",
          'title' => $this->t('Workflow'),
          'base_route' => "entity.$entity_type_id.canonical",
          'weight' => 100,
        ];
      }
    }

    foreach ($this->derivatives as &$entry) {
      $entry += $base_plugin_definition;
    }

    return $this->derivatives;
  }

This is obviously wrong, and gives the wrong fieldname if its not the last workflow field set.

Trying to dig into derivative routes to find a correct solution but posted in case other might have the issue or know more.

el1_1el’s picture

Here is a patch that fixes it, but might introduce errors if someone has multiple workflows on a single entity so Im not uploading for testing yet.

diff --git a/src/Routing/RouteSubscriber.php b/src/Routing/RouteSubscriber.php
index 66e5b25..dd34870 100644
--- a/src/Routing/RouteSubscriber.php
+++ b/src/Routing/RouteSubscriber.php
@@ -46,18 +46,11 @@ protected function alterRoutes(RouteCollection $collection) {
        * one workflow fields.
        */
 
-      // Only 1 field. Workflow is redirect to workflow/{field_name}.
-      if (count($fields) < 2) {
-        $path = "/$entityTypeId/{{$entityTypeId}}/workflow";
-        $route = $this->getEntityLoadRoute($entityTypeId, $path);
-        $collection->add("entity.$entityTypeId.workflow_history", $route);
-      }
-
       // Generate one route for each workflow field.
       foreach ($fields as $field_name => $field) {
-        $path = "/$entityTypeId/{{$entityTypeId}}/workflow/$field_name";
+        $path = "/$entityTypeId/{{$entityTypeId}}/workflow";
         $route = $this->getEntityLoadRoute($entityTypeId, $path);
-        $collection->add("entity.$entityTypeId.workflow_history.$field_name", $route);
+        $collection->add("entity.$entityTypeId.workflow_history", $route);
       }
     }
   }

Only other option I can think of would be to load the entity and check for the presence of the field being loaded. Which probably would not occur within the RouteSubscriber->alterRoutes or in WorkflowLocalTask->getDerivativeDefinitions

el1_1el’s picture

Version: 8.x-1.1 » 8.x-1.x-dev
Status: Active » Needs review
Related issues: +#2584953: Display 'Workflow history tab' for each entity type
StatusFileSize
new752 bytes

So after a lot of manual testing on this, it looks to me like the
entity.$entityTypeId.workflow_history
route is never registered because I have 3 workflow fields on 3 different bundles.

Since there are no checks for bundles, and I have 3 fields, this line
if (count($fields) < 2) {
in src/Routing/RouteSubscriber.php alterRoutes method prevents the workflow_history route from registering and only registers routes as
entity.$entityTypeId.workflow_history.$field_name and i get the fatal error.

I attached a simple patch to always register the workflow_history route in the router table preventing the fatal error.

Of note, this does not allow for entities with multiple workflow fields to have multiple tabs associated with each workflow.
However, when i tried that (see comment 4 and change
$this->derivatives["entity.$entity_type_id.workflow_history"] = [
to
$this->derivatives["entity.$entity_type_id.workflow_history.$fieldname"] = [
it would show tabs for every workflow field on every bundle and would not route to the correct associated workflow regardless.

I also tried adding 2 more workflow fields and associated them with new workflows on a single bundle. Even manually typing the second fieldname (ie node/nid/workflow/field_name) still brought me to the first workflow.

So I'm wondering if https://www.drupal.org/project/workflow/issues/2584953 might need more work.

  • johnv committed a18ef2e on 8.x-1.x authored by el1_1el
    Issue #2969569 by el1_1el: RouteNotFoundException for Entities with...
johnv’s picture

Title: Upgrading to 1.1 breaks routes on all nodes with workflow » RouteNotFoundException for Entities with different Workflow Field per bundle
Version: 8.x-1.x-dev » 8.x-1.1
Priority: Major » Normal
Status: Needs review » Fixed

I committed your proposal.
Indeed, your usecase is not completely satisfied: there is no history tab for each workflow field, only a route.
This is documented in the code.
You may open a new issue for this. (supplort for multiple fields s an ongoing task in D8)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

johnv’s picture

Title: RouteNotFoundException for Entities with different Workflow Field per bundle » RouteNotFoundException for Entities with multiple Workflow Fields per bundle
johnv’s picture

Title: RouteNotFoundException for Entities with multiple Workflow Fields per bundle » Route "entity.node.workflow_history" error for Entities with multiple Workflow Fields per bundle