Problem:

Currently, on the Latest Version tab, only transitions in which the “from” and “to” states are different from each other are included. We need to include transitions in which the “from” and “to” states are the same.
We need to add this capability so that:

  • A workflow participant who is allowed to keep an item in its current state, but is not allowed to move an item to a different state, can still provide feedback on an item.
  • A workflow participant who is allowed to both keep an item in its current state and move an item to a different state can provide feedback on an item without changing its current state.

https://www.drupal.org/files/issues/self-transition.png

in the code:

// Exclude self-transitions.
    $transitions = array_filter($transitions, function(ModerationStateTransition $transition) use ($current_state) {
      return $transition->getToState() != $current_state->id();
    });


Proposed solution:

https://www.drupal.org/files/issues/proposed-solution.png

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pericxc created an issue. See original summary.

pericxc’s picture

Issue summary: View changes
Crell’s picture

I'm not sure I'd bother with the checkbox. If self-transitions are going to be allowed, let's just allow them.

pericxc’s picture

This patch excludes checkbox.

pericxc’s picture

Status: Active » Needs review
pericxc’s picture

pericxc’s picture

pericxc’s picture

Assigned: Unassigned » pericxc
pericxc’s picture

pericxc’s picture

Status: Needs review » Needs work
pericxc’s picture

pericxc’s picture

Status: Needs work » Needs review
pericxc’s picture

Version: 8.x-2.x-dev » 8.x-1.x-dev
pericxc’s picture

Crell’s picture

+++ b/src/Entity/ModerationStateTransition.php
@@ -141,4 +141,11 @@ class ModerationStateTransition extends ConfigEntityBase implements ModerationSt
+    return (!$self_transition && ($this->getToState() === $this->getFromState())) ? 'Keep in ' . $this->getToState() : parent::label();

This isn't going to be translatable. It needs to use t().

jhedstrom’s picture

+++ b/src/Entity/ModerationStateTransition.php
@@ -141,4 +145,12 @@ class ModerationStateTransition extends ConfigEntityBase implements ModerationSt
+  public function label($self_transition = TRUE) {
+    return (!$self_transition && ($this->getToState() === $this->getFromState())) ?
+      $this->t('Keep in %to', ['%to' => $this->getToState()]) : parent::label();
+  }

Since there can be little context when translating strings, how about changing %to to something more verbose like %moderation_state perhaps?

Also, can you add a code comment here explaining the logic? I had to read it a few times to grasp how this would work.

I think adding something to one of the tests to verify this would be worthwhile too.

jhedstrom’s picture

Just 2 coding standard nits and then I think this is good to go!

+++ b/src/Entity/ModerationStateTransition.php
@@ -141,4 +145,16 @@ class ModerationStateTransition extends ConfigEntityBase implements ModerationSt
+     // State Transition label will change when fromState and toState are the same and
+     // input $arg = FALSE, to: 'Keep in <transition-state>'.

+++ b/src/Tests/ModerationStateTransitionsTest.php
@@ -86,6 +88,28 @@ class ModerationStateTransitionsTest extends ModerationStateTestBase {
+    // Verify that Labels are identical in case where from and to states are different.

These comments exceed the 80-character length, and should wrap onto another line.

jhedstrom’s picture

I think this is good to go. Thanks for working on this @pericxc!

scookie’s picture

This is just an observation: It looks like self-transitions used to be there, but were removed.
https://www.drupal.org/node/2651196

larowlan’s picture

This will conflict with #2715689: Allow overridable action button labels for transitions.

@jhedstrom which would you prefer went in first, I'm voting for #2715689: Allow overridable action button labels for transitions.

jhedstrom’s picture

@larowlan either is fine by me. I'm not sure if I'll have time to keep this up though as the focus of the projects I'm working on is now core's Content Moderation modules...