Problem/Motivation

Follow-up from #2779647: Add a workflow component, ui module, and implement it in content moderation. Workflow::setTransitionFormStates() currently does not allow having multiple workflow transitions which have (an) identical (or at least overlapping) from state(s) and an identical to state:

  public function setTransitionFromStates($transition_id, array $from_state_ids) {
    ...

    foreach ($from_state_ids as $from_state_id) {
      ...

      if ($this->hasTransitionFromStateToState($from_state_id, $this->transitions[$transition_id]['to'])) {
        $transition = $this->getTransitionFromStateToState($from_state_id, $this->transitions[$transition_id]['to']);
        if ($transition_id !== $transition->id()) {
          throw new \InvalidArgumentException("The '{$transition->id()}' transition already allows '$from_state_id' to '{$this->transitions[$transition_id]['to']}' transitions in workflow '{$this->id()}'");
        }
      }
    }

    ...
  }

The benefit of this is that given a from and to state, we can determine the transition ID.

There are valid use-cases for this, though, that are not possible because of this. Quoting @tstoeckler in #2779647-125: Add a workflow component, ui module, and implement it in content moderation:

I can see why we do this, but I can also see two reasons against it:

  1. Having a transition that is a superset (in terms of the from states) of another transition that is only available to privileged users. This can also be solved by making to transitions where the from states do not overlap, so this is only a half-reason, but it's not completely invalid because the superset could possibly make for a better UI in terms of labelling, etc.
  2. We actually have the concept of "Change classes" in our project, i.e. if you only fix a typo it triggers something different than if you only change content. This could also be solved by adding additional states (possibly with auto-transitions) so is also only a half-reason, but I wanted to bring it up.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

tstoeckler created an issue. See original summary.

tstoeckler’s picture

By the way, having mulled over this a bit, I am fine with this being marked won't fix, as I do appreciate that the current behavior avoids/prevents a lot of complexity, but wanted to open this in order to provide a place for a proper discussion.

timmillwood’s picture

Issue tags: +Workflow Initiative

I think this is an interesting discussion to have, I am also fine with this being "won't fix" but interested to hear real use cases.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

LiamPower’s picture

Edit: Actually the transitions don't help with my use case

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

sime’s picture

I am currently using Workflow Buttons module which takes a transition name and exposes it as a button. This has been working exceptionally well to give the user a much better sense of what they are trying to achieve rather than what the end moderation state will be.

For example a user sees a button [Save Progress] (the name of the transition) and this might push content from Published to Incomplete.

With this in place I can also add triggers when certain transitions are used using Workbench Email. This means that when [Save Progress] is triggered I can send an email to that says "Hey well done for saving progress, but you'll need to come back later and finish the job".

So, now I want to add a transition [Request Review] and the permissions are set such that only Managers can execute this. This transition can also move content from Published to Incomplete. This means that I can send an different email when this transition is executed ("Hey a manager asked you to review your thing"), as it has a different intention that than the transition that normal users can use.

There are a couple of considerations...

  • Workflow Buttons module is simply looking at the options on the form by default and finding the best transition. Maybe it could do it a different way and load the transitions that are applicable. This then makes the problem one that can be solved in Workflow Buttons.
  • If I was to use the ECA module it works by detecting the FROM->TO state and doesn't offer an ability to detect the transition used.

In the end, I can't understand why we needed to prevent additional transitions that cover the same FROM->TO. It doesn't make any sense why this is enforced, and if it wasn't enforce it would allow more creative ways for contrib module to leverage the "transition as a verb" idea that was lost when core replaced buttons with a state drop-down.

sime’s picture

The benefit of this is that given a from and to state, we can determine the transition ID.

This is a benefit but not critical - we can already order transitions, so determining the appropraite transition is a case of:

  1. What transitions are valid for these from/to states
  2. What transitions does the user have permission to use
  3. Which transition has the highest priority.