summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-04-04 13:21:50 (GMT)
committerAlex Pott2018-04-04 13:21:50 (GMT)
commit19d0533ffa7c9f0d254134b0e485778c901499b9 (patch)
tree823997918034a71de935a3eaa943d3b2633149bf
parent39183a2956dece217329e78c836f78da9e8d7804 (diff)
Issue #2927408 by Anas_maw, Erik Frèrejean, timmillwood, Sam152, catch: Default value not correctly set in the ModerationStateWidget
-rw-r--r--core/modules/content_moderation/src/Plugin/Field/FieldWidget/ModerationStateWidget.php3
-rw-r--r--core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php4
2 files changed, 7 insertions, 0 deletions
diff --git a/core/modules/content_moderation/src/Plugin/Field/FieldWidget/ModerationStateWidget.php b/core/modules/content_moderation/src/Plugin/Field/FieldWidget/ModerationStateWidget.php
index 967dce8..8a33c76 100644
--- a/core/modules/content_moderation/src/Plugin/Field/FieldWidget/ModerationStateWidget.php
+++ b/core/modules/content_moderation/src/Plugin/Field/FieldWidget/ModerationStateWidget.php
@@ -131,6 +131,9 @@ class ModerationStateWidget extends OptionsSelectWidget implements ContainerFact
foreach ($transitions as $transition) {
$transition_to_state = $transition->to();
$transition_labels[$transition_to_state->id()] = $transition_to_state->label();
+ if ($default->id() === $transition_to_state->id()) {
+ $default_value = $default->id();
+ }
}
$element += [
diff --git a/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php
index bb9e92d..76d25f2 100644
--- a/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php
+++ b/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php
@@ -107,6 +107,10 @@ class ModerationFormTest extends ModerationStateTestBase {
'moderation_state[0][state]' => 'published',
], t('Save'));
+ // Check widget default value.
+ $this->drupalGet($edit_path);
+ $this->assertFieldByName('moderation_state[0][state]', 'published', 'The moderation default value is set correctly.');
+
// The published view should not have a moderation form, because it is the
// live revision.
$this->drupalGet($canonical_path);