Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#21 | set_widget_default_value-2927408-21.patch | 1.63 KB | Anas_maw |
#14 | set_widget_default_value-2927408-14.patch | 1.65 KB | Anas_maw |
#10 | set_widget_default_value-2927408-10.patch | 1.63 KB | Anas_maw |
#4 | set_widget_default_value-2927408-4.patch | 832 bytes | Erik Frèrejean |
#2 | set_widget_default_value-2927408-2.patch | 1.3 KB | Erik Frèrejean |
Comments
Comment #2
Erik FrèrejeanComment #3
timmillwoodyeh, 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.
Comment #4
Erik FrèrejeanWell 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.Comment #5
timmillwoodI 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 😉.
Comment #7
Anas_maw CreditAttribution: Anas_maw as a volunteer commentedComment #8
Anas_maw CreditAttribution: Anas_maw as a volunteer commentedI can confirm patch #4 working well.
Comment #9
timmillwoodAs stated in #5, this needs tests!
Comment #10
Anas_maw CreditAttribution: Anas_maw as a volunteer commentedSorry for this misunderstanding, i'm not very good with tests but i think that i got it.
Please review.
Comment #11
bkosborneThanks 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.
Comment #12
timmillwoodLooks good, thanks for adding the test @Anas_maw!
Comment #13
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedTiny 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!
Comment #14
Anas_maw CreditAttribution: Anas_maw as a volunteer commented@Sam152 You are right, here is an updated patch with the suggested message.
Comment #15
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedLooks great, thanks!
Comment #16
pifagorLooks good for me.
Comment #18
Anas_maw CreditAttribution: Anas_maw as a volunteer commentedComment #19
MixologicTemporary testbot hiccup.
Comment #20
catchShouldn't the message just be "The moderation default value is set correctly."?
Comment #21
Anas_maw CreditAttribution: Anas_maw at Coders Enterprise Web & Mobile Solutions commentedUpdated with the suggested message.
Comment #22
timmillwoodComment #23
alexpottCredited @timmillwood, @Sam152 and @catch as they made comments that impacted the patch.
Comment #24
alexpottCommitted and pushed 19d0533ffa to 8.6.x and 0b35eb08fe to 8.5.x. Thanks!
Comment #28
alisonHi! 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
Comment #29
Anas_maw CreditAttribution: Anas_maw as a volunteer commented@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.
Comment #30
alisonOh oh okay, thank you I absolutely will!
Comment #31
alisonDone -- thanks again, @Anas_maw!
#2990926: Node type: Default publishing option won't save as Published