Problem/Motivation

The default value in Drupal\content_moderation\Plugin\Field\FieldWidget\ModerationStateWidget::formElement is always set to NULL rather then the current selected state.

Proposed resolution

Fix the default value.

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Erik Frèrejean created an issue. See original summary.

Erik Frèrejean’s picture

Status: Active » Needs review
FileSize
1.3 KB
timmillwood’s picture

Status: Needs review » Needs work
Issue tags: +Workflow Initiative, +Needs tests

yeh, that is a bit weird isn't it?

The issue with setting it to the current state is that the current state might not always be a valid transition, so we'd need check if the current state is in $transition_labels before setting it as the default.

Also this needs tests for the default value and the case stated above.

Erik Frèrejean’s picture

yeh, that is a bit weird isn't it?

Well more then weird, I'm getting swamped with complaints from some editors that published nodes suddenly gets unpublished because it doesn't maintain the correct default value. That said, to me it feels quite counterintuitive that maintaining a state isn't a valid transition (but there are probably reasons for that ;))

I've updated the patch to check whether $default is part of $transition_labels, but am not familiar enough the testing framework/workflow/content moderation to quickly whip up some tests for it. So would be great if someone who is can give a hand with that part.

timmillwood’s picture

I think the only state that ships with core that can't be maintained is "Archived", when editing an archived entity it has to move then either to be a new draft or published.

New patch looks like a nice solution, but still needs tests 😉.

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

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.

Anas_maw’s picture

Status: Needs work » Needs review
Anas_maw’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm patch #4 working well.

timmillwood’s picture

Status: Reviewed & tested by the community » Needs work

As stated in #5, this needs tests!

Anas_maw’s picture

Status: Needs work » Needs review
FileSize
1.63 KB

Sorry for this misunderstanding, i'm not very good with tests but i think that i got it.
Please review.

bkosborne’s picture

Thanks for reporting this! I'm migrating from workbench moderation and saw this strange behavior as well. I think the approach taken makes perfect sense - default to the current transition if available, otherwise just use the first.

As for the tests, I think a bit more work can be done for the tests for better coverage - basically to test that the current state is selected when it's available in the list, and that the first item is selected otherwise.

timmillwood’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Looks good, thanks for adding the test @Anas_maw!

Sam152’s picture

+++ b/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php
@@ -107,6 +107,10 @@ public function testModerationForm() {
+    // Check widget default value.
+    $this->drupalGet($edit_path);
+    $this->assertFieldByName('moderation_state[0][state]', 'published', 'Moderation state default value is not set.');

Tiny nit: in the assertion messages we should write the expected behavior, "the default moderation state value was set correctly" or "expected the moderation state default value to be set correctly" and the test runner would highlight the correctness of the statement.

If the assertion was passing, it would be confusing the see a message saying "moderation state default value is not set". You would assume this was the intended behavior when it is in fact the opposite!

Anas_maw’s picture

@Sam152 You are right, here is an updated patch with the suggested message.

Sam152’s picture

Looks great, thanks!

pifagor’s picture

Looks good for me.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 14: set_widget_default_value-2927408-14.patch, failed testing. View results

Anas_maw’s picture

Status: Needs work » Needs review
Mixologic’s picture

Status: Needs review » Reviewed & tested by the community

Temporary testbot hiccup.

catch’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php
@@ -107,6 +107,10 @@ public function testModerationForm() {
+    $this->assertFieldByName('moderation_state[0][state]', 'published', 'Expected the moderation state default value to be set correctly.');

Shouldn't the message just be "The moderation default value is set correctly."?

Anas_maw’s picture

Status: Needs work » Needs review
FileSize
1.63 KB

Updated with the suggested message.

timmillwood’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Credited @timmillwood, @Sam152 and @catch as they made comments that impacted the patch.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 19d0533ffa to 8.6.x and 0b35eb08fe to 8.5.x. Thanks!

  • alexpott committed 19d0533 on 8.6.x
    Issue #2927408 by Anas_maw, Erik Frèrejean, timmillwood, Sam152, catch:...

  • alexpott committed 0b35eb0 on 8.5.x
    Issue #2927408 by Anas_maw, Erik Frèrejean, timmillwood, Sam152, catch:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

alison’s picture

Hi! Somehow I've *gained* this problem since updating from Drupal 8.5.3 to 8.5.6 -- I'm sure it's me, seeing as no one's commented on this issue since April, and the patch was included in 8.5.4 which has been out for over two months -- but I'm really not sure how to try to figure out why it's happening to me now. Did y'all go thru any regressions while creating/testing/applying these changes...?

>> What's happening to me (just to make sure it is indeed the same issue):
-- I edit a content type (admin/structure/types/manage/mytype)
-- Publishing options > Default options > "Published" is unchecked
-- I enable "Published"
-- I save the form
-- I edit that same ctype again (admin/structure/types/manage/mytype)
-- Publishing options > Default options > "Published" is unchecked

Anas_maw’s picture

@alisonjo2786
This issue was for the content, not for the content type settings form.
I went through the steps you provided, and yes i found the same problem.
I this you should open a separate ticket for this issue.

alison’s picture

Oh oh okay, thank you I absolutely will!

alison’s picture