Problem/Motivation

  • Moderation states and translation with the same label confuses user to associate them with a role. They appear as duplicate records. When duplicate record is found, adding machine name along with its label name would solve the problem.

When duplicate records exists with same label, this is how state transition looks on edit role's permissions page:

permissions

Proposed resolution

Display the machine name of the state alongside the label - ONLY if transition states are duplicates. For example, here is the state transition overview with the machine name in parentheses:

solution

Related issue

This patch will take care of #2738903: Multiple moderation states with the same label are confusing in the transition UI

related

CommentFileSizeAuthor
#46 workbench_moderation-2750365-46.patch8.02 KBpericxc
#46 interdiff-workbench_moderation-2750365-45-46.txt672 bytespericxc
#45 workbench_moderation-2750365-45.patch7.96 KBpericxc
#45 interdiff-workbench_moderation-2750365-40-45.txt548 bytespericxc
#40 workbench_moderation-2750365-40.patch7.97 KBpericxc
#40 interdiff-workbench_moderation-2750365-31-40.txt3.65 KBpericxc
#35 workbench_moderation-2738869-32.patch5.71 KBpericxc
#35 interdiff-workbench_moderation-2738869-31-32.txt1.14 KBpericxc
#31 Screenshot 2016-07-15 15.21.28.png50.1 KBlarowlan
#31 2750365-duplicate-labels.31.patch4.52 KBlarowlan
#31 interdiff.txt9.15 KBlarowlan
#26 workbench_moderation-2750365-07.patch5.57 KBpericxc
#26 interdiff-workbench_moderation-2750365-06-07.txt1.54 KBpericxc
#25 missing machine_name in Manage moderation.png125.06 KBswathikris
#22 workbench_moderation-2750365-06.patch4.6 KBpericxc
#22 interdiff-workbench_moderation-2750365-05-06.txt2.65 KBpericxc
#19 workbench_moderation-2750365-05.patch5.45 KBpericxc
#19 interdiff-workbench_moderation-2750365-04-05.txt782 bytespericxc
#17 Screen Shot 2016-06-20 at 10.57.19 AM.png57.04 KBpericxc
#16 workbench_moderation-2750365-04.patch5.45 KBpericxc
#16 interdiff-workbench_moderation-2750365-03-04.txt4.7 KBpericxc
#12 workbench_moderation-2750365-03.patch3.79 KBpericxc
#12 interdiff-workbench_moderation-2750365-02-03.txt1.7 KBpericxc
#7 interdiff-workbench_moderation-2750365-01-02.txt2.54 KBpericxc
#7 workbench_moderation-2750365-02.patch2.48 KBpericxc
#6 Screen Shot 2016-06-16 at 3.05.09 PM.png54.58 KBpericxc
#2 workbench_moderation-2750365-01.patch1.11 KBpericxc
Screen Shot 2016-06-16 at 11.32.39 AM.png57.55 KBpericxc
Screen Shot 2016-06-16 at 11.02.32 AM.png52.84 KBpericxc

Comments

pericxc created an issue. See original summary.

pericxc’s picture

StatusFileSize
new1.11 KB
pericxc’s picture

Status: Active » Needs review
jhedstrom’s picture

I wonder if for both this issue, and over in #2738903: Multiple moderation states with the same label are confusing in the transition UI if we should rather than always add the machine name, first check to see if there are any duplicatly named transition states? That way, simple sites would continue to get the UX they have now without the machine name, and more complex sites would get the clarifying machine name.

pericxc’s picture

Issue summary: View changes
pericxc’s picture

Issue summary: View changes
StatusFileSize
new54.58 KB
pericxc’s picture

pericxc’s picture

I just created a new patch with changed logic. First it will to check if there are any duplicately named transition states, then only for those will add machine name.

pericxc’s picture

Issue summary: View changes
jhedstrom’s picture

This is looking really good.

One nitpick:

+++ b/src/Permissions.php
@@ -48,2 +56,24 @@
+  private function getUniqueLabels($args) {

Protected functions are preferred to private in Drupal coding standards.

jhedstrom’s picture

Also, we need to make sure this method will allow the work in #2738903: Multiple moderation states with the same label are confusing in the transition UI to use the same logic. If not, a more general utility method should be introduced I think.

pericxc’s picture

pericxc’s picture

jhedstrom’s picture

+++ b/src/Form/ModerationStateTransitionForm.php
@@ -68,9 +70,12 @@ class ModerationStateTransitionForm extends EntityForm {
+    $states = ModerationState::loadMultiple();
+    $unique_labels = Permissions::getUniqueLabels($states);

Since this is being used for both permissions and moderation state forms, perhaps the new method (getUniqueLabels()) should be on the ModerationStateInterface interface (and thus ModerationState class) itself?

pericxc’s picture

make sense, but It also should be added to the ModerationStateTransition and ModerationStateTransitioninterface.

pericxc’s picture

pericxc’s picture

Issue summary: View changes
StatusFileSize
new57.04 KB
jhedstrom’s picture

One last nitpick and I think this is ready!

+++ b/src/Entity/ModerationState.php
@@ -78,4 +78,20 @@ class ModerationState extends ConfigEntityBase implements ModerationStateInterfa
+    foreach (self::loadMultiple() as $arg) {

While this probably won't matter here, in general, rather than self::, static:: is preferred since then final control of which method is used is left to the implementing class (see Late static bindings for further detail).

pericxc’s picture

jhedstrom’s picture

Status: Needs review » Reviewed & tested by the community

This looks great. For simple sites, there will be no noticeable change to the UI, but for complex sites with multiple transitions that might share a label, this is a big usability enhancement.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/src/Entity/ModerationState.php
@@ -78,4 +78,20 @@ class ModerationState extends ConfigEntityBase implements ModerationStateInterfa
+  public static function getUniqueLabels() {

diff --git a/src/Entity/ModerationStateTransition.php b/src/Entity/ModerationStateTransition.php
index 75e098c..7a4dbfc 100644

+++ b/src/Entity/ModerationStateTransition.php
@@ -141,4 +141,23 @@ class ModerationStateTransition extends ConfigEntityBase implements ModerationSt
+  public static function getUniqueLabels() {

This is essentially the same code - could we have it in a trait instead?

Other than that, I reckon this is ready to go

pericxc’s picture

pericxc’s picture

Status: Needs work » Needs review
jhedstrom’s picture

Status: Needs review » Reviewed & tested by the community

This looks good to go!

swathikris’s picture

StatusFileSize
new125.06 KB

Hi @pericxc, thanks for this enhancement where in machine_name is displayed if there were any duplicate state label names.
We'll need to display machine_name in 'Manage moderation' page. While any content type enables moderation, machine_name display on this page is very helpful. Please see the attached screen grab - missing machine_name in Manage moderation.png

missing machine name

Thank you

pericxc’s picture

webchick’s picture

Following up from #2757349: WI: Deal with scalability issues in the UI, which mentioned the cluttering of the permissions page. This patch unfortunately makes it worse. :( Spun off #2766467: Permissions: Make the permission description the name and drop the description to cut down UI clutter to talk about fixing this, since the other changes look good.

pericxc’s picture

@webchick, you mentioned there are scalability issues this patch introduces, which is the valid point. Just wondering what are the next steps to get this patch committed?

webchick’s picture

That I don't know, since I'm not a maintainer of this module. I'm guessing though that one of them will see this and respond soon. :)

larowlan’s picture

As pointed out in #25 I think this 'fix it where we see it' approach is bound to miss some places.

Going to try a different approach.

larowlan’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new9.15 KB
new4.52 KB
new50.1 KB

This is the approach.

So the default label() method will always return the unique label.

No need to override it elsewhere.

Then if we need a non-unique label (eg in places where showing the original value in the form or when we're showing the nice names in the content edit form and machine names are inappropriate) we pass FALSE argument.

That way every other place the label is shown that there are duplicates, we don't need special code.

We can control when we are calling label(), but we can't control every other place in core and contrib etc. So we flip it.

This way, the default behaviour is enough.

Screenshots show no difference to previous patch.

Thoughts?

larowlan’s picture

Also @pericxc to answer your question, I'm doing reviews of RTBC issues in modules I maintain every Friday with view to commit. This one was on today's list but I think we're not quite there yet.

pericxc’s picture

@larowlan, that's great. It also resolved another issue, I was about to create, on page "admin/structure/workbench-moderation/transitions". machine_names are now displayed!

pericxc’s picture

@larowlan, so two things has to be done: a test and related suggestions from https://www.drupal.org/node/2766467, right?

pericxc’s picture

A small change related to #2766467

Status: Needs review » Needs work

The last submitted patch, 35: workbench_moderation-2738869-32.patch, failed testing.

The last submitted patch, 35: workbench_moderation-2738869-32.patch, failed testing.

The last submitted patch, 35: workbench_moderation-2738869-32.patch, failed testing.

pericxc’s picture

pericxc’s picture

pericxc’s picture

Status: Needs work » Needs review
pericxc’s picture

In the last patch I removed description and added Web Test.

chx’s picture

If I were writing this:

  public static function getNonUniqueLabels() {
    $labels = [];

    foreach (static::loadMultiple() as $arg) {
      $label = $arg->label(FALSE);
      $labels[$label] = isset($labels[$label]);
    }
    
    return array_filter($labels);
  }
pericxc’s picture

@chx, yep. changing it. thx.

pericxc’s picture

pericxc’s picture

jhedstrom’s picture

Status: Needs review » Reviewed & tested by the community

I think this has addressed all the outstanding points above. The code going in here can be refactored as needed for #2766467: Permissions: Make the permission description the name and drop the description to cut down UI clutter without too much effort I think.

I've manually tested this as well with multiple states with the same label.

larowlan’s picture

Thanks, will commit on Friday all going to plan

alexpott’s picture

Why don't we enforce unique labels?

jhedstrom’s picture

Why don't we enforce unique labels?

Sites with many different workflows can have the same label (eg, Draft) for multiple states since these are site wide, and a state transition for one entity type might have completely different permissions than a state for another entity type.

alexpott’s picture

I think core is planning on going a different way here. Having global states and transitions doesn't really make make sense. We're thinking of taking a similar approach to workflow. See #2779647: Add a workflow component, ui module, and implement it in content moderation

jhedstrom’s picture

Adding related core content moderation issue.