diff --git a/core/modules/content_moderation/src/EntityOperations.php b/core/modules/content_moderation/src/EntityOperations.php index 36e2d9d..4418741 100644 --- a/core/modules/content_moderation/src/EntityOperations.php +++ b/core/modules/content_moderation/src/EntityOperations.php @@ -104,7 +104,7 @@ public function entityPresave(EntityInterface $entity) { $workflows = $this->moderationInfo->getWorkFlowsForEntity($entity); $workflow = reset($workflows); /** @var \Drupal\content_moderation\ContentModerationState $current_state */ - $current_state = $workflow->getState($entity->moderation_state->getValue()[0][$workflow->id()]); + $current_state = $workflow->getState($entity->moderation_state->state); // This entity is default if it is new, the default revision, or the // default revision is not published. @@ -281,7 +281,7 @@ protected function isDefaultRevisionPublished(EntityInterface $entity, WorkflowI $default_revision = $default_revision->getTranslation($entity->language()->getId()); } - return $default_revision && $workflow->getState($default_revision->moderation_state->value)->isPublishedState(); + return $default_revision && $workflow->getState($default_revision->moderation_state->state)->isPublishedState(); } } diff --git a/core/modules/content_moderation/src/EntityTypeInfo.php b/core/modules/content_moderation/src/EntityTypeInfo.php index 3e8826b..e332dd1 100644 --- a/core/modules/content_moderation/src/EntityTypeInfo.php +++ b/core/modules/content_moderation/src/EntityTypeInfo.php @@ -308,11 +308,11 @@ public function entityBaseFieldInfo(EntityTypeInterface $entity_type) { } $fields = []; - $fields['moderation_state'] = BaseFieldDefinition::create('map') + $fields['moderation_state'] = BaseFieldDefinition::create('moderation_state') ->setLabel(t('Moderation state')) ->setDescription(t('The moderation state of this piece of content.')) ->setComputed(TRUE) - ->setClass(ModerationStateFieldItemList::class) + //->setClass(ModerationStateFieldItemList::class) ->setSetting('target_type', 'moderation_state') ->setDisplayOptions('view', [ 'label' => 'hidden', diff --git a/core/modules/content_moderation/src/Form/EntityModerationForm.php b/core/modules/content_moderation/src/Form/EntityModerationForm.php index 6e4daea..aebf7c2 100644 --- a/core/modules/content_moderation/src/Form/EntityModerationForm.php +++ b/core/modules/content_moderation/src/Form/EntityModerationForm.php @@ -63,7 +63,7 @@ public function getFormId() { * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, ContentEntityInterface $entity = NULL) { - $current_state = $entity->moderation_state->value; + $current_state = $entity->moderation_state->state; $workflow = $this->moderationInfo->getWorkflowForEntity($entity); /** @var \Drupal\workflows\Transition[] $transitions */ diff --git a/core/modules/content_moderation/src/ModerationInformation.php b/core/modules/content_moderation/src/ModerationInformation.php index bbf0853..09373e2 100644 --- a/core/modules/content_moderation/src/ModerationInformation.php +++ b/core/modules/content_moderation/src/ModerationInformation.php @@ -130,11 +130,12 @@ public function hasForwardRevision(ContentEntityInterface $entity) { * {@inheritdoc} */ public function isLiveRevision(ContentEntityInterface $entity) { - $workflow = $this->getWorkflowForEntity($entity); + $workflows = $this->getWorkflowsForEntity($entity); + $workflow = reset($workflow); return $this->isLatestRevision($entity) && $entity->isDefaultRevision() - && $entity->moderation_state->value - && $workflow->getState($entity->moderation_state->value)->isPublishedState(); + && $entity->moderation_state->state + && $workflow->getState($entity->moderation_state->state)->isPublishedState(); } /** diff --git a/core/modules/content_moderation/src/Plugin/Field/FieldType/ModerationStateItem.php b/core/modules/content_moderation/src/Plugin/Field/FieldType/ModerationStateItem.php index e69de29..f5fdaea 100644 --- a/core/modules/content_moderation/src/Plugin/Field/FieldType/ModerationStateItem.php +++ b/core/modules/content_moderation/src/Plugin/Field/FieldType/ModerationStateItem.php @@ -0,0 +1,83 @@ +setLabel(new TranslatableMarkup('State ID')) + ->setDescription(new TranslatableMarkup('The id of the state.')) + ->setRequired(TRUE); + + $properties['workflow'] = DataReferenceDefinition::create('entity') + ->setLabel(new TranslatableMarkup('Workflow')) + ->setDescription(new TranslatableMarkup('The referenced entity')) + ->setTargetDefinition(EntityDataDefinition::create('workflow')); + + return $properties; + } + + /** + * @inheritDoc + */ + public static function schema(FieldStorageDefinitionInterface $field_definition) { + return []; + } + + /** + * @inheritDoc + */ + public function setValue($values, $notify = TRUE) { + parent::setValue($values, $notify); // TODO: Change the autogenerated stub + } + + /** + * @inheritDoc + */ + public function getValue() { + return parent::getValue(); // TODO: Change the autogenerated stub + } + + /** + * @inheritDoc + */ + public function set($property_name, $value, $notify = TRUE) { + return parent::set($property_name, $value, $notify); // TODO: Change the autogenerated stub + } + + /** + * @inheritDoc + */ + public function applyDefaultValue($notify = TRUE) { + $entity = $this->getEntity(); + $moderation_info = \Drupal::service('content_moderation.moderation_information'); + $workflows = $moderation_info->getWorkFlowsForEntity($entity); + foreach ($workflows as $workflow) { + $this->setValue([ + 'state' => $workflow->getInitialState()->id(), + 'workflow' => $workflow, + ]); + } + return $this; + } + + +} \ No newline at end of file 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 7fe5a6d..e9e308f 100644 --- a/core/modules/content_moderation/src/Plugin/Field/FieldWidget/ModerationStateWidget.php +++ b/core/modules/content_moderation/src/Plugin/Field/FieldWidget/ModerationStateWidget.php @@ -21,7 +21,7 @@ * id = "moderation_state_default", * label = @Translation("Moderation state"), * field_types = { - * "string" + * "moderation_state" * } * ) */ @@ -116,8 +116,9 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen return $element + ['#access' => FALSE]; } - $workflow = $this->moderationInformation->getWorkflowForEntity($entity); - $default = $items->get($delta)->value ? $workflow->getState($items->get($delta)->value) : $workflow->getInitialState(); + $workflows = $this->moderationInformation->getWorkflowsForEntity($entity); + $workflow = reset($workflows); + $default = $items->get($delta)->state ? $workflow->getState($items->get($delta)->state) : $workflow->getInitialState(); if (!$default) { throw new \UnexpectedValueException(sprintf('The %s bundle has an invalid moderation state configuration, moderation states are enabled but no default is set.', $bundle_entity->label())); } @@ -161,7 +162,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen public static function updateStatus($entity_type_id, ContentEntityInterface $entity, array $form, FormStateInterface $form_state) { $element = $form_state->getTriggeringElement(); if (isset($element['#moderation_state'])) { - $entity->moderation_state->value = $element['#moderation_state']; + $entity->moderation_state->state = $element['#moderation_state']; } } diff --git a/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php b/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php index 133b51e..f1c175c 100644 --- a/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php +++ b/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php @@ -40,7 +40,7 @@ protected function getModerationStateId() { // Existing entities will have a corresponding content_moderation_state // entity associated with them. if (!$entity->isNew() && $content_moderation_state = $this->loadContentModerationStateRevision($entity)) { - return $content_moderation_state->moderation_state->value; + return $content_moderation_state->moderation_state->state; } // It is possible that the bundle does not exist at this point. For example, diff --git a/core/modules/content_moderation/src/Plugin/Validation/Constraint/ModerationStateConstraintValidator.php b/core/modules/content_moderation/src/Plugin/Validation/Constraint/ModerationStateConstraintValidator.php index d9308e8..2742668 100644 --- a/core/modules/content_moderation/src/Plugin/Validation/Constraint/ModerationStateConstraintValidator.php +++ b/core/modules/content_moderation/src/Plugin/Validation/Constraint/ModerationStateConstraintValidator.php @@ -92,9 +92,10 @@ public function validate($value, Constraint $constraint) { $original_entity = $original_entity->getTranslation($entity->language()->getId()); } - $workflow = $this->moderationInformation->getWorkflowForEntity($entity); - $new_state = $workflow->getState($entity->moderation_state->value) ?: $workflow->getInitialState(); - $original_state = $workflow->getState($original_entity->moderation_state->value); + $workflows = $this->moderationInformation->getWorkflowsForEntity($entity); + $workflow = reset($workflows); + $new_state = $workflow->getState($entity->moderation_state->state) ?: $workflow->getInitialState(); + $original_state = $workflow->getState($original_entity->moderation_state->state); // @todo - what if $new_state references something that does not exist or // is null. if (!$original_state->canTransitionTo($new_state->id())) { diff --git a/core/modules/content_moderation/src/StateTransitionValidation.php b/core/modules/content_moderation/src/StateTransitionValidation.php index c4e26c2..9fc4dae 100644 --- a/core/modules/content_moderation/src/StateTransitionValidation.php +++ b/core/modules/content_moderation/src/StateTransitionValidation.php @@ -39,8 +39,9 @@ public function __construct(ModerationInformationInterface $moderation_info) { * {@inheritdoc} */ public function getValidTransitions(ContentEntityInterface $entity, AccountInterface $user) { - $workflow = $this->moderationInfo->getWorkflowForEntity($entity); - $current_state = $entity->moderation_state->value ? $workflow->getState($entity->moderation_state->value) : $workflow->getInitialState(); + $workflows = $this->moderationInfo->getWorkflowsForEntity($entity); + $workflow = reset($workflows); + $current_state = $entity->moderation_state->state ? $workflow->getState($entity->moderation_state->state) : $workflow->getInitialState(); return array_filter($current_state->getTransitions(), function(Transition $transition) use ($workflow, $user) { return $user->hasPermission('use ' . $workflow->id() . ' transition ' . $transition->id()); diff --git a/core/modules/content_moderation/src/Tests/ModerationLocaleTest.php b/core/modules/content_moderation/src/Tests/ModerationLocaleTest.php index a78c104..662387e 100644 --- a/core/modules/content_moderation/src/Tests/ModerationLocaleTest.php +++ b/core/modules/content_moderation/src/Tests/ModerationLocaleTest.php @@ -97,9 +97,9 @@ public function testTranslateModeratedContent() { $french_node = $english_node->getTranslation('fr'); $this->assertEqual('French node', $french_node->label()); - $this->assertEqual($english_node->moderation_state->value, 'published'); + $this->assertEqual($english_node->moderation_state->state, 'published'); $this->assertTrue($english_node->isPublished()); - $this->assertEqual($french_node->moderation_state->value, 'draft'); + $this->assertEqual($french_node->moderation_state->state, 'draft'); $this->assertFalse($french_node->isPublished()); // Create another article with its translation. This time we will publish @@ -127,9 +127,9 @@ public function testTranslateModeratedContent() { $this->assertText(t('Article Translated node has been updated.')); $english_node = $this->drupalGetNodeByTitle('Another node', TRUE); $french_node = $english_node->getTranslation('fr'); - $this->assertEqual($french_node->moderation_state->value, 'published'); + $this->assertEqual($french_node->moderation_state->state, 'published'); $this->assertTrue($french_node->isPublished()); - $this->assertEqual($english_node->moderation_state->value, 'draft'); + $this->assertEqual($english_node->moderation_state->state, 'draft'); $this->assertFalse($english_node->isPublished()); // Now check that we can create a new draft of the translation. @@ -140,7 +140,7 @@ public function testTranslateModeratedContent() { $this->assertText(t('Article New draft of translated node has been updated.')); $english_node = $this->drupalGetNodeByTitle('Another node', TRUE); $french_node = $english_node->getTranslation('fr'); - $this->assertEqual($french_node->moderation_state->value, 'published'); + $this->assertEqual($french_node->moderation_state->state, 'published'); $this->assertTrue($french_node->isPublished()); $this->assertEqual($french_node->getTitle(), 'Translated node', 'The default revision of the published translation remains the same.'); @@ -152,7 +152,7 @@ public function testTranslateModeratedContent() { $this->assertText(t('The moderation state has been updated.')); $english_node = $this->drupalGetNodeByTitle('Another node', TRUE); $french_node = $english_node->getTranslation('fr'); - $this->assertEqual($french_node->moderation_state->value, 'published'); + $this->assertEqual($french_node->moderation_state->state, 'published'); $this->assertTrue($french_node->isPublished()); $this->assertEqual($french_node->getTitle(), 'New draft of translated node', 'The draft has replaced the published revision.'); @@ -160,7 +160,7 @@ public function testTranslateModeratedContent() { $this->drupalPostForm('node/' . $english_node->id() . '/edit', [], t('Save and Publish (this translation)')); $this->assertText(t('Article Another node has been updated.')); $english_node = $this->drupalGetNodeByTitle('Another node', TRUE); - $this->assertEqual($english_node->moderation_state->value, 'published'); + $this->assertEqual($english_node->moderation_state->state, 'published'); // Archive the node and its translation. $this->drupalPostForm('node/' . $english_node->id() . '/edit', [], t('Save and Archive (this translation)')); @@ -169,9 +169,9 @@ public function testTranslateModeratedContent() { $this->assertText(t('Article New draft of translated node has been updated.')); $english_node = $this->drupalGetNodeByTitle('Another node', TRUE); $french_node = $english_node->getTranslation('fr'); - $this->assertEqual($english_node->moderation_state->value, 'archived'); + $this->assertEqual($english_node->moderation_state->state, 'archived'); $this->assertFalse($english_node->isPublished()); - $this->assertEqual($french_node->moderation_state->value, 'archived'); + $this->assertEqual($french_node->moderation_state->state, 'archived'); $this->assertFalse($french_node->isPublished()); // Create another article with its translation. This time publishing english diff --git a/core/modules/content_moderation/src/Tests/ModerationStateNodeTest.php b/core/modules/content_moderation/src/Tests/ModerationStateNodeTest.php index a89ec9f..e79ea18 100644 --- a/core/modules/content_moderation/src/Tests/ModerationStateNodeTest.php +++ b/core/modules/content_moderation/src/Tests/ModerationStateNodeTest.php @@ -34,7 +34,7 @@ public function testCreatingContent() { if (!$node) { $this->fail('Test node was not saved correctly.'); } - $this->assertEqual('draft', $node->moderation_state->value); + $this->assertEqual('draft', $node->moderation_state->state); $path = 'node/' . $node->id() . '/edit'; // Set up published revision. @@ -43,7 +43,7 @@ public function testCreatingContent() { /* @var \Drupal\node\NodeInterface $node */ $node = \Drupal::entityTypeManager()->getStorage('node')->load($node->id()); $this->assertTrue($node->isPublished()); - $this->assertEqual('published', $node->moderation_state->value); + $this->assertEqual('published', $node->moderation_state->state); // Verify that the state field is not shown. $this->assertNoText('Published'); @@ -70,7 +70,7 @@ public function testCreatingContent() { if (!$node) { $this->fail('Non-moderated test node was not saved correctly.'); } - $this->assertEqual(NULL, $node->moderation_state->value); + $this->assertEqual(NULL, $node->moderation_state->state); // \Drupal\content_moderation\Form\BundleModerationConfigurationForm() // should not list workflows with no states. diff --git a/core/modules/content_moderation/tests/src/Functional/LatestRevisionViewsFilterTest.php b/core/modules/content_moderation/tests/src/Functional/LatestRevisionViewsFilterTest.php index cf14b23..af97247 100644 --- a/core/modules/content_moderation/tests/src/Functional/LatestRevisionViewsFilterTest.php +++ b/core/modules/content_moderation/tests/src/Functional/LatestRevisionViewsFilterTest.php @@ -57,7 +57,7 @@ public function testViewShowsCorrectNids() { 'title' => 'Node 1 - Rev 1', 'uid' => $editor1->id(), ]); - $node_1->moderation_state->value = 'draft'; + $node_1->moderation_state->state = 'draft'; $node_1->save(); // Make a node that is in Draft, then Published. @@ -67,11 +67,11 @@ public function testViewShowsCorrectNids() { 'title' => 'Node 2 - Rev 1', 'uid' => $editor1->id(), ]); - $node_2->moderation_state->value = 'draft'; + $node_2->moderation_state->state = 'draft'; $node_2->save(); $node_2->setTitle('Node 2 - Rev 2'); - $node_2->moderation_state->value = 'published'; + $node_2->moderation_state->state = 'published'; $node_2->save(); // Make a node that is in Draft, then Published, then Draft. @@ -81,15 +81,15 @@ public function testViewShowsCorrectNids() { 'title' => 'Node 3 - Rev 1', 'uid' => $editor1->id(), ]); - $node_3->moderation_state->value = 'draft'; + $node_3->moderation_state->state = 'draft'; $node_3->save(); $node_3->setTitle('Node 3 - Rev 2'); - $node_3->moderation_state->value = 'published'; + $node_3->moderation_state->state = 'published'; $node_3->save(); $node_3->setTitle('Node 3 - Rev 3'); - $node_3->moderation_state->value = 'draft'; + $node_3->moderation_state->state = 'draft'; $node_3->save(); // Now show the View, and confirm that only the correct titles are showing. diff --git a/core/modules/content_moderation/tests/src/Functional/ModerationActionsTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationActionsTest.php index 32d10fa..c9df01f 100644 --- a/core/modules/content_moderation/tests/src/Functional/ModerationActionsTest.php +++ b/core/modules/content_moderation/tests/src/Functional/ModerationActionsTest.php @@ -63,7 +63,7 @@ public function testNodeStatusActions($action, $bundle, $warning_appears, $start 'status' => $starting_status, ]); if ($bundle == 'moderated_bundle') { - $node->moderation_state->value = $starting_status ? 'published' : 'draft'; + $node->moderation_state->state = $starting_status ? 'published' : 'draft'; } $node->save(); diff --git a/core/modules/content_moderation/tests/src/Functional/ModerationStateAccessTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationStateAccessTest.php index 7d2f746..094f934 100644 --- a/core/modules/content_moderation/tests/src/Functional/ModerationStateAccessTest.php +++ b/core/modules/content_moderation/tests/src/Functional/ModerationStateAccessTest.php @@ -42,7 +42,7 @@ public function testViewShowsCorrectStates() { 'title' => 'Draft node', 'uid' => $editor1->id(), ]); - $node_1->moderation_state->value = 'draft'; + $node_1->moderation_state->state = 'draft'; $node_1->save(); $node_2 = Node::create([ @@ -50,12 +50,12 @@ public function testViewShowsCorrectStates() { 'title' => 'Published node', 'uid' => $editor1->id(), ]); - $node_2->moderation_state->value = 'published'; + $node_2->moderation_state->state = 'published'; $node_2->save(); // Resave the node with a new state. $node_2->setTitle('Archived node'); - $node_2->moderation_state->value = 'archived'; + $node_2->moderation_state->state = 'archived'; $node_2->save(); // Now show the View, and confirm that the state labels are showing. diff --git a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php index 69bb580..e0dce88 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php @@ -95,13 +95,13 @@ public function testBasicModeration($entity_type_id) { ]); $entity->save(); $entity = $this->reloadEntity($entity); - $this->assertEquals('draft', $entity->moderation_state->value); + $this->assertEquals('draft', $entity->moderation_state->state); - $entity->moderation_state->value = 'published'; + $entity->moderation_state->state = 'published'; $entity->save(); $entity = $this->reloadEntity($entity); - $this->assertEquals('published', $entity->moderation_state->value); + $this->assertEquals('published', $entity->moderation_state->state); // Change the state without saving the node. $content_moderation_state = ContentModerationState::load(1); @@ -110,7 +110,7 @@ public function testBasicModeration($entity_type_id) { $content_moderation_state->save(); $entity = $this->reloadEntity($entity, 3); - $this->assertEquals('draft', $entity->moderation_state->value); + $this->assertEquals('draft', $entity->moderation_state->state); if ($entity instanceof EntityPublishedInterface) { $this->assertFalse($entity->isPublished()); } @@ -122,11 +122,11 @@ public function testBasicModeration($entity_type_id) { } $this->assertEquals(2, $entity->getRevisionId()); - $entity->moderation_state->value = 'published'; + $entity->moderation_state->state = 'published'; $entity->save(); $entity = $this->reloadEntity($entity, 4); - $this->assertEquals('published', $entity->moderation_state->value); + $this->assertEquals('published', $entity->moderation_state->state); // Get the default revision. $entity = $this->reloadEntity($entity); @@ -136,7 +136,7 @@ public function testBasicModeration($entity_type_id) { $this->assertEquals(4, $entity->getRevisionId()); // Update the node to archived which will then be the default revision. - $entity->moderation_state->value = 'archived'; + $entity->moderation_state->state = 'archived'; $entity->save(); // Revert to the previous (published) revision. @@ -147,7 +147,7 @@ public function testBasicModeration($entity_type_id) { // Get the default revision. $entity = $this->reloadEntity($entity); - $this->assertEquals('published', $entity->moderation_state->value); + $this->assertEquals('published', $entity->moderation_state->state); if ($entity instanceof EntityPublishedInterface) { $this->assertTrue($entity->isPublished()); } @@ -199,7 +199,7 @@ public function testMultilingualModeration() { $english_node ->setUnpublished() ->save(); - $this->assertEquals('draft', $english_node->moderation_state->value); + $this->assertEquals('draft', $english_node->moderation_state->state); $this->assertFalse($english_node->isPublished()); // Create a French translation. @@ -208,34 +208,34 @@ public function testMultilingualModeration() { // Revision 1 (fr). $french_node->save(); $french_node = $this->reloadEntity($english_node)->getTranslation('fr'); - $this->assertEquals('draft', $french_node->moderation_state->value); + $this->assertEquals('draft', $french_node->moderation_state->state); $this->assertFalse($french_node->isPublished()); // Move English node to create another draft. $english_node = $this->reloadEntity($english_node); - $english_node->moderation_state->value = 'draft'; + $english_node->moderation_state->state = 'draft'; // Revision 2 (en, fr). $english_node->save(); $english_node = $this->reloadEntity($english_node); - $this->assertEquals('draft', $english_node->moderation_state->value); + $this->assertEquals('draft', $english_node->moderation_state->state); // French node should still be in draft. $french_node = $this->reloadEntity($english_node)->getTranslation('fr'); - $this->assertEquals('draft', $french_node->moderation_state->value); + $this->assertEquals('draft', $french_node->moderation_state->state); // Publish the French node. - $french_node->moderation_state->value = 'published'; + $french_node->moderation_state->state = 'published'; // Revision 3 (en, fr). $french_node->save(); $french_node = $this->reloadEntity($french_node)->getTranslation('fr'); $this->assertTrue($french_node->isPublished()); - $this->assertEquals('published', $french_node->moderation_state->value); + $this->assertEquals('published', $french_node->moderation_state->state); $this->assertTrue($french_node->isPublished()); $english_node = $french_node->getTranslation('en'); - $this->assertEquals('draft', $english_node->moderation_state->value); + $this->assertEquals('draft', $english_node->moderation_state->state); // Publish the English node. - $english_node->moderation_state->value = 'published'; + $english_node->moderation_state->state = 'published'; // Revision 4 (en, fr). $english_node->save(); $english_node = $this->reloadEntity($english_node); @@ -244,7 +244,7 @@ public function testMultilingualModeration() { // Move the French node back to draft. $french_node = $this->reloadEntity($english_node)->getTranslation('fr'); $this->assertTrue($french_node->isPublished()); - $french_node->moderation_state->value = 'draft'; + $french_node->moderation_state->state = 'draft'; // Revision 5 (en, fr). $french_node->save(); $french_node = $this->reloadEntity($english_node, 5)->getTranslation('fr'); @@ -252,7 +252,7 @@ public function testMultilingualModeration() { $this->assertTrue($french_node->getTranslation('en')->isPublished()); // Republish the French node. - $french_node->moderation_state->value = 'published'; + $french_node->moderation_state->state = 'published'; // Revision 6 (en, fr). $french_node->save(); $french_node = $this->reloadEntity($english_node)->getTranslation('fr'); @@ -266,9 +266,9 @@ public function testMultilingualModeration() { $content_moderation_state->save(); $english_node = $this->reloadEntity($french_node, $french_node->getRevisionId() + 1); - $this->assertEquals('draft', $english_node->moderation_state->value); + $this->assertEquals('draft', $english_node->moderation_state->state); $french_node = $this->reloadEntity($english_node)->getTranslation('fr'); - $this->assertEquals('published', $french_node->moderation_state->value); + $this->assertEquals('published', $french_node->moderation_state->state); // This should unpublish the French node. $content_moderation_state = ContentModerationState::load(1); @@ -279,9 +279,9 @@ public function testMultilingualModeration() { $content_moderation_state->save(); $english_node = $this->reloadEntity($english_node, $english_node->getRevisionId()); - $this->assertEquals('draft', $english_node->moderation_state->value); + $this->assertEquals('draft', $english_node->moderation_state->state); $french_node = $this->reloadEntity($english_node, '8')->getTranslation('fr'); - $this->assertEquals('draft', $french_node->moderation_state->value); + $this->assertEquals('draft', $french_node->moderation_state->state); // Switching the moderation state to an unpublished state should update the // entity. $this->assertFalse($french_node->isPublished()); @@ -318,12 +318,12 @@ public function testNonTranslatableEntityTypeModeration() { 'type' => 'example' ]); $entity_test_with_bundle->save(); - $this->assertEquals('draft', $entity_test_with_bundle->moderation_state->value); + $this->assertEquals('draft', $entity_test_with_bundle->moderation_state->state); - $entity_test_with_bundle->moderation_state->value = 'published'; + $entity_test_with_bundle->moderation_state->state = 'published'; $entity_test_with_bundle->save(); - $this->assertEquals('published', EntityTestWithBundle::load($entity_test_with_bundle->id())->moderation_state->value); + $this->assertEquals('published', EntityTestWithBundle::load($entity_test_with_bundle->id())->moderation_state->state); } /** @@ -354,12 +354,12 @@ public function testNonLangcodeEntityTypeModeration() { 'type' => 'example' ]); $entity_test_with_bundle->save(); - $this->assertEquals('draft', $entity_test_with_bundle->moderation_state->value); + $this->assertEquals('draft', $entity_test_with_bundle->moderation_state->state); - $entity_test_with_bundle->moderation_state->value = 'published'; + $entity_test_with_bundle->moderation_state->state = 'published'; $entity_test_with_bundle->save(); - $this->assertEquals('published', EntityTestWithBundle::load($entity_test_with_bundle->id())->moderation_state->value); + $this->assertEquals('published', EntityTestWithBundle::load($entity_test_with_bundle->id())->moderation_state->state); } /** diff --git a/core/modules/content_moderation/tests/src/Kernel/EntityOperationsTest.php b/core/modules/content_moderation/tests/src/Kernel/EntityOperationsTest.php index 60e9edf..8c42e5b 100644 --- a/core/modules/content_moderation/tests/src/Kernel/EntityOperationsTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/EntityOperationsTest.php @@ -63,7 +63,7 @@ public function testForwardRevisions() { 'type' => 'page', 'title' => 'A', ]); - $page->moderation_state->value = 'draft'; + $page->moderation_state->state = 'draft'; $page->save(); $id = $page->id(); @@ -78,7 +78,7 @@ public function testForwardRevisions() { // Moderate the entity to published. $page->setTitle('B'); - $page->moderation_state->value = 'published'; + $page->moderation_state->state = 'published'; $page->save(); // Verify the entity is now published and public. @@ -89,7 +89,7 @@ public function testForwardRevisions() { // Make a new forward-revision in Draft. $page->setTitle('C'); - $page->moderation_state->value = 'draft'; + $page->moderation_state->state = 'draft'; $page->save(); // Verify normal loads return the still-default previous version. @@ -108,7 +108,7 @@ public function testForwardRevisions() { $this->assertEquals('C', $page->getTitle()); $page->setTitle('D'); - $page->moderation_state->value = 'published'; + $page->moderation_state->state = 'published'; $page->save(); // Verify normal loads return the still-default previous version. @@ -119,7 +119,7 @@ public function testForwardRevisions() { // Now check that we can immediately add a new published revision over it. $page->setTitle('E'); - $page->moderation_state->value = 'published'; + $page->moderation_state->state = 'published'; $page->save(); $page = Node::load($id); @@ -137,7 +137,7 @@ public function testPublishedCreation() { 'type' => 'page', 'title' => 'A', ]); - $page->moderation_state->value = 'published'; + $page->moderation_state->state = 'published'; $page->save(); $id = $page->id(); @@ -159,7 +159,7 @@ public function testArchive() { 'title' => $this->randomString(), ]); - $page->moderation_state->value = 'published'; + $page->moderation_state->state = 'published'; $page->save(); $id = $page->id(); @@ -170,7 +170,7 @@ public function testArchive() { // When the page is moderated to the archived state, then the latest // revision should be the default revision, and it should be unpublished. - $page->moderation_state->value = 'archived'; + $page->moderation_state->state = 'archived'; $page->save(); $new_revision_id = $page->getRevisionId(); diff --git a/core/modules/content_moderation/tests/src/Kernel/EntityRevisionConverterTest.php b/core/modules/content_moderation/tests/src/Kernel/EntityRevisionConverterTest.php index 6f209d1..04b90ed 100644 --- a/core/modules/content_moderation/tests/src/Kernel/EntityRevisionConverterTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/EntityRevisionConverterTest.php @@ -75,7 +75,7 @@ public function testConvertWithRevisionableEntityType() { 'title' => 'test', 'type' => 'article', ]); - $node->moderation_state->value = 'published'; + $node->moderation_state->state = 'published'; $node->save(); $revision_ids[] = $node->getRevisionId(); @@ -85,7 +85,7 @@ public function testConvertWithRevisionableEntityType() { $revision_ids[] = $node->getRevisionId(); $node->setNewRevision(TRUE); - $node->moderation_state->value = 'draft'; + $node->moderation_state->state = 'draft'; $node->save(); $revision_ids[] = $node->getRevisionId(); diff --git a/core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php b/core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php index 7c4f97d..1ee012b 100644 --- a/core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/EntityStateChangeValidationTest.php @@ -58,14 +58,14 @@ public function testValidTransition() { 'type' => 'example', 'title' => 'Test title', ]); - $node->moderation_state->value = 'draft'; + $node->moderation_state->state = 'draft'; $node->save(); - $node->moderation_state->value = 'published'; + $node->moderation_state->state = 'published'; $this->assertCount(0, $node->validate()); $node->save(); - $this->assertEquals('published', $node->moderation_state->value); + $this->assertEquals('published', $node->moderation_state->state); } /** @@ -86,10 +86,10 @@ public function testInvalidTransition() { 'type' => 'example', 'title' => 'Test title', ]); - $node->moderation_state->value = 'draft'; + $node->moderation_state->state = 'draft'; $node->save(); - $node->moderation_state->value = 'archived'; + $node->moderation_state->state = 'archived'; $violations = $node->validate(); $this->assertCount(1, $violations); diff --git a/core/modules/content_moderation/tests/src/Kernel/ViewsDataIntegrationTest.php b/core/modules/content_moderation/tests/src/Kernel/ViewsDataIntegrationTest.php index 6b127c8..c9c7b95 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ViewsDataIntegrationTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ViewsDataIntegrationTest.php @@ -57,14 +57,14 @@ public function testViewsData() { 'type' => 'page', 'title' => 'Test title first revision', ]); - $node->moderation_state->value = 'published'; + $node->moderation_state->state = 'published'; $node->save(); $revision = clone $node; $revision->setNewRevision(TRUE); $revision->isDefaultRevision(FALSE); $revision->title->value = 'Test title second revision'; - $revision->moderation_state->value = 'draft'; + $revision->moderation_state->state = 'draft'; $revision->save(); $view = Views::getView('test_content_moderation_latest_revision'); @@ -94,14 +94,14 @@ public function testContentModerationStateRevisionJoin() { 'type' => 'page', 'title' => 'Test title first revision', ]); - $node->moderation_state->value = 'published'; + $node->moderation_state->state = 'published'; $node->save(); $revision = clone $node; $revision->setNewRevision(TRUE); $revision->isDefaultRevision(FALSE); $revision->title->value = 'Test title second revision'; - $revision->moderation_state->value = 'draft'; + $revision->moderation_state->state = 'draft'; $revision->save(); $view = Views::getView('test_content_moderation_revision_test'); @@ -128,14 +128,14 @@ public function testContentModerationStateBaseJoin() { 'type' => 'page', 'title' => 'Test title first revision', ]); - $node->moderation_state->value = 'published'; + $node->moderation_state->state = 'published'; $node->save(); $revision = clone $node; $revision->setNewRevision(TRUE); $revision->isDefaultRevision(FALSE); $revision->title->value = 'Test title second revision'; - $revision->moderation_state->value = 'draft'; + $revision->moderation_state->state = 'draft'; $revision->save(); $view = Views::getView('test_content_moderation_base_table_test'); diff --git a/core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php b/core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php index 2e03447..7dd99d3 100644 --- a/core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php +++ b/core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php @@ -44,7 +44,7 @@ public function testUserSensitiveValidTransitions($from_id, $to_id, $permission, $entity = $this->prophesize(ContentEntityInterface::class); $entity = $entity->reveal(); $entity->moderation_state = new \stdClass(); - $entity->moderation_state->value = $from_id; + $entity->moderation_state->state = $from_id; $validator = new StateTransitionValidation($this->setUpModerationInformation($entity)); $has_transition = FALSE;