In version 7.x-2.x, the Workflow History tab is enabled for each entity type.
In version 8.x-1.x, this is only done for Nodes, and for TaxonomyTerms (as Proof of Concept for any non-Node Entity type.)

A volunteer is requested to add the History tab for any entity type. This requires creating a new route. The DEVEL module contains a '{entity}/devel' tab for each entity type, which can serve as an example:
- \modules\devel\src\Plugin\Derivative\DevelLocalTask.php
- \modules\devel\src\Routing\RouteSubscriber
- \modules\devel\devel.service.yml

In Workflow:
- change \modules\workflow\src\Controller\WorkflowTransitionListController.php
- replace the routes in workflow.routing.yml with the generic solution

If you only want to proved a path to your own custom entity:
- use workflow.routing.yml as an example path
- provide a patch for the problem you encounter in WorkflowTransitionListController.php

Comments

johnv created an issue. See original summary.

  • johnv committed 32e5901 on 8.x-1.x
    Issue #2584953: [D8-port task] Add Workflow History Tab for each entity...
johnv’s picture

Adjacent commit removes the D7 hook_menu_alter(). It should be replaced by the D8-code.

(hmm, somehow the commit does not show up. But the D7-version of hook_menu_alter can be a source of information for this task.)

afi13’s picture

Assigned: Unassigned » afi13
afi13’s picture

Assigned: afi13 » Unassigned
mikejw’s picture

Assigned: Unassigned » mikejw
johnv’s picture

Title: [D8-port task] Add Workflow History Tab for each entity type. » Display 'Workflow history tab' for each entity type
Category: Task » Feature request
estoyausente’s picture

Hi!
I started the task but I have a doubt:

I could see this kind of path:
"/node/{$entity_type_id}/workflow/{field_name}"

What is {field_name} ? I need to provide a correct Routes before try to resolve the problems in WorkflowTransitionListController.php.

Anyone can review my code and give me a hand to complete a correct RouteSubscriber.php? With this completet I supose that I will can go to /mycustomentity/{$entity_type_id}/workflow/{field_name} and see the workflow history. After it, I will try to resolve the problems in WorkflowTransitionListController.php and provide the tabs in WorkflowLocalTask.php.

Thanks in advance!

EDIT:
I just found that you have to create a field for the entity wo attach the workflow to the entity. You cannot attach the workflow to a no-fieldable entity without bundler? Thanks in advance!

johnv’s picture

Hi, Thanks in advance.

An entity type can have 0, 1 or more Workflow fields. (It should not be possible to add a Workflow Field without adding a Worflow type to it. Please open a new issue if you can.)

Yout path does not seem correct: /node/1/workflow -->

/{entity_type}/{$entity_id}/workflow/

Be careful, you may test with Taxonomy terms. there the path is something like /taxonomy/term/1/workflow.

- no workflows: /{entity_type}/{$entity_id}/workflow/ does not exist
- one workflow: /{entity_type}/{$entity_id}/workflow/ and /{entity_type}/{$entity_id}/workflow/{field_name} Are the same.
- more workfows: both paths exist:
-- /{entity_type}/{$entity_id}/workflow/{field_name_1}
-- /{entity_type}/{$entity_id}/workflow/{field_name_2}, and
-- /{entity_type}/{$entity_id}/workflow/ defaults to one of the fields field_name_1 or field_name_2

estoyausente’s picture

Hi,

thanks for the comment. I already have a valid Route, now I want to change it following your comments and suggest.

FYI: I just created a new issue with the non-fieldable entitites (https://www.drupal.org/project/workflow/issues/2942532) but is not too important for my use case because I changed my current entity and made it fieldable. I prefer work on this feature (and I think that is more important).

estoyausente’s picture

StatusFileSize
new11.57 KB

Hi again,

I think that now the Route class has better color. I think that in the case of the a entity has more than one workflow field we should show a list of them, but I don't develop this behavior, only the others. Now the Route works correctly I think. Please if you can take a look while I continue with the LocalTask and the other stuff implementations it would be great for me.

estoyausente’s picture

Assigned: mikejw » Unassigned
StatusFileSize
new20.19 KB
new9.66 KB

Hi all!

I think that all work is more less finished (except the taxonomy term code that needs a review). The routes seems works for Nodes and custom entities, the permission function is adapted (and now are in his own class, I think that is more clear) and the workflow_url_get_entity function in the .module is adapted too.

I think that we can review the current behavior and create the taxonomy adaptation before adapt the code to the new D8 style (for example, removing the .module helper functions and create services and classes to replicate the behaviors).

Somebody can check my patch and review with me? The use cases are so differents and it's difficult develop changes without risks (and I never used this module before in any Drupal version).

Thanks for all guys!

estoyausente’s picture

Status: Active » Needs review

Hi,

What we need to do to apply this patch? I think that it's a very important part of the module and I'm confusing about the next step.

manuel.adan’s picture

I recently created a new module for workflows, transaction workflow. It is based on the transaction module, so it works with any content entity type. It is not intended to be a replacement for the workflow module, just another approach based as much as possible on existing and standard components.

johnv’s picture

Hi manual adan, I have copied your comment to a new issue, so it will not get lost: #2960767: Assess new module Transaction Workflow

  • johnv committed 5047485 on 8.x-1.x
    Issue #2584953 by estoyausente, johnv: Display 'Workflow history tab'...
johnv’s picture

Status: Needs review » Reviewed & tested by the community

@estoyausente, I had an elaborate comment on your patch, but it got lost...
I added your patch with some modifications.

johnv’s picture

- I replaced the function public static function listWorkflowFieldsByEntities() by a one-liner workflow_get_workflow_fields_by_entity_type().
I could have just changed the contents...
- The RouteSubscriber gives an error in my IDE: " Other declaration of class RouteSubscriber exist "
- Is RouteSubscriber::listWorkflowFields() still used?
- variable _workflow_entity_type_id is not used anymore in workflow_url_get_entity, since it was not always filled, e.g., on the workflow tab page. See also the contents of that function.

estoyausente’s picture

Ok, @johnv, I will replace your new dev version in my project removing my patch and I will test it. I will let you know something about the test and about your comments.

Thanks.

estoyausente’s picture

Status: Reviewed & tested by the community » Fixed

After some weeks of test in a real production environment ( but in a little project only worked with my company mates ) the workflow with custom entities seems ok!

If I found improvements I will open other issues.

Thanks!

Status: Fixed » Closed (fixed)

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