Problem/Motivation

The moderation state field is configurable in form displays, but it doesn't seem to respect its configured weight. Even if you move the moderation state to the top of the form display, it will still be displayed towards the bottom.

Screenshots, from #16:

If you move the moderation state to the top of the form...

...it still shows up at the bottom.

Proposed resolution

Fix it!

Remaining tasks

Write a patch, with tests, and commit it. Wash, rinse, repeat.

User interface changes

None.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

KelvinWong created an issue. See original summary.

KelvinWong’s picture

Making moderation_state field configurable in node form.

KelvinWong’s picture

Status: Active » Needs review
phenaproxima’s picture

Status: Needs review » Needs work
+++ b/docroot/profiles/lightning/modules/lightning_features/lightning_workflow/lightning_workflow.module
@@ -129,3 +130,18 @@ function lightning_workflow_views_pre_render(ViewExecutable $view) {
+function lightning_workflow_entity_base_field_info_alter(&$fields, $entity_type) {
+
+  foreach ($fields as $definition) {
+    // Set configurable form display for language fields with display options.
+    if ($definition->toArray()['field_name'] == 'moderation_state') {
+      $definition->setDisplayConfigurable('form', TRUE);
+    }
+  }

This is a nice find and a good solution, but let's change this to something a little more efficient. Assuming the fields are keyed by name (and they should be), this could be something like:

if (isset($fields['moderation_state'])) {
  $fields['moderation_state']->setDisplayConfigurable('form', TRUE);
}

We will probably also need a test of some sort, to prove that the field is actually made configurable. A kernel test oughta do the trick; all it would need to do is install the entity schema of a moderatable entity type, ensure that moderation is enabled for it, then assert that the moderation_state field is marked as configurable.

Another option would be to simply file this patch against Workbench Moderation itself, and Lightning could bring the patch in. That would be preferable, in fact, since more people could then have this fix without needing to use Lightning.

KelvinWong’s picture

Thanks phenaproxima, the patch is updated.

This patch is not application for the original Workbench Moderation module, as the state options they provided are embedded in the submit button, so the field doesn't need to be configurable. It will be a good idea if Workbench Moderation module provides options to choose between a standard submit button and a submit button with moderation states dropdown.

I will also give the kernel test a go.

bkosborne’s picture

Thanks for working on this... was driving me nuts. Let me know if you need a hand Kelvin, I can take a shot at the tests as well.

balsama’s picture

bkosborne’s picture

There's a patch for this in WBM: #2833892: The ability to rearrange moderation state field in the form

But as I noted there, this change also allows site builders to change the field widget off of the one provided by workbench moderation. Using any other field widget makes no sense and could introduce confusion and bugs.

I wonder if there's another way around this =/

amenity’s picture

I agree with @bkosborne, this patch isn't yet ideal. However, since the intent of Lightning is to allow developers to improve the editorial experience, I'd err on the side of making it confusing for site builders rather than muddying the editor UX.

balsama’s picture

Assigned: Unassigned » phenaproxima

Let's see if we can use WBM patch and set sane defaults.

KelvinWong’s picture

Status: Needs work » Needs review
FileSize
45.6 KB

I don't think that is an issue with WBM. The moderation state field is embedded in the submit button by default. See attached screenshot. Hence there is no need to set the weight of it, as it is always showing up together with the submit button.

It is however, the lightning_workflow feature overriding the default behaviour of the moderation_state field, and have it as a separated dropdown field. That is why we have to enable weight setting, otherwise the field will always have a default weight of 5.

KelvinWong’s picture

Added updated patch. This patch is tested with lightning 8.x-2.17.

phenaproxima’s picture

Component: User interface » Workflow
Status: Needs review » Postponed

We're currently in the process of building an upgrade path from Workbench Moderation to Content Moderation. So I'd like to postpone this on that.

balsama’s picture

Status: Postponed » Active

Just tested this on Lightning 2.2.5 (with Content Moderation) and the problem still exists. But, I also confirmed identical behavior with the standard install profile. So this doesn't appear to be Lightning-specific.

phenaproxima’s picture

Title: The weight of moderation_state field is not changeable. » The weight of moderation_state field is not changeable
Project: Lightning » Drupal core
Version: 8.x-2.17 » 8.5.x-dev
Component: Workflow » content_moderation.module
Category: Feature request » Bug report
Issue summary: View changes

Okay, we need to move this to core. Thanks for testing, @balsama!

balsama’s picture

Some screen shots for clarity. Move the "Moderation state" field above title:
Form Display

But it remains at the bottom of the form:
Result

phenaproxima’s picture

Issue summary: View changes

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.

Wim Leers’s picture

AFAICT this exact bug was reported again exactly one year later: #2925182: Content moderation widget cannot be reordered

dpi’s picture

Status: Active » Closed (duplicate)

Marking as duplicate of #2925182: Content moderation widget cannot be reordered since that issue was in the core queue before this one.

Feel free to continue discussion there, or move back to Lightning.