Views sort WorkflowState by Weight (D8)

Created on 4 February 2024, 12 months ago
Updated 1 March 2024, 11 months ago

Problem/Motivation

It would be good to have a sort criteria that is based in state's weight.

In the states management like this:
/admin/config/workflow/workflow/name_your_wf/states

there is a weight field to order the states.

This goes to configuration but I didn't test with module like Configuration Views .

Anyone has come to a solution on this?

Feature request
Status

Active

Version

1.0

Component

Miscellaneous

Created by

🇵🇹Portugal jrochate

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

Comments & Activities

  • Issue created by @jrochate
  • 🇳🇱Netherlands johnv

    You might want to add a relation to the states.

  • 🇵🇹Portugal jrochate

    hi @johnv. thank you for your time, but that suggestion doesn't work for the use-case initially defined:

    - I have a workflow with states. And that states can haver an order defined by weight
    /admin/config/workflow/workflow/my_wf/states

    - I would like to build a view where the content is sorted using states weight and not states title

    Using a relationship, I can only relate to workflow_transition, and that won't work since I don't have weight in there.

    So what would work is a relation to the config since states are configs and not entity... in theory.

  • 🇳🇱Netherlands johnv

    Is this module of any use? :
    Views Sort By Options Weight

    I haven't checked it, but I may incorporate it.

  • 🇵🇹Portugal jrochate

    I have tested that module, and also checked the source code, and that is very hard do extend.

    We would need to patch it very hard in order to get "set weight", since it's not pluggable.

    To that kind of work, it would be preferable to make a new View sort handler specific to workflow.

    namespace Drupal\workflow\Plugin\views\sort;
    
    use Drupal\views\Plugin\views\sort\SortPluginBase;

    and then explore from here.

    I don't know workflow module to make this work quickly. What do you think about this approach?

  • 🇳🇱Netherlands johnv

    Yes, I have checked that too.
    It seems best to indeed create a custom sort handler.
    Not sure if I will start on this soon, since I am cleaning up the big openissue list ATM.

    A file needs to be copied from views module, into \workflow\src\Plugin\views\sort.
    It should read all config transitions or config states, then sort on weight.

    When you do sorting, it would be nice if the workflwo type is fetched also, since there are issues with multiple workflows.

  • 🇳🇱Netherlands johnv

    Please check if this issue is a duplicate of Views sort WorkflowState field by Weight/Label Active if so, let's continue over there.

  • 🇵🇹Portugal jrochate

    I will try and see if a views sort handler can be done here, and thank you for your reply.

    I have checked the other issue, and I think the OP is having problems in using multiple tables that come from distinct views blocks, and he has problems in sorting the columns.

    here the problem is not specific to Table but views in general, where we don't have the handler available.
    So I would keep it separate, if you don't mind.

Production build 0.71.5 2024