Commit aa45adec authored by catch's avatar catch

Issue #2881645 by jhedstrom, tstoeckler, Sam152, timmillwood, plach:...

Issue #2881645 by jhedstrom, tstoeckler, Sam152, timmillwood, plach: ContentModerationState 'workflow' column empty for all non-default translations
parent ab03340b
......@@ -67,7 +67,6 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
->setDescription(t('The workflow the moderation state is in.'))
->setSetting('target_type', 'workflow')
->setRequired(TRUE)
->setTranslatable(TRUE)
->setRevisionable(TRUE);
$fields['moderation_state'] = BaseFieldDefinition::create('string')
......
......@@ -83,6 +83,7 @@ public function testMultilingual() {
$this->assertEquals('draft', $english_node->moderation_state->value);
$this->assertFalse($english_node->isPublished());
$this->assertTrue($english_node->isDefaultRevision());
$this->assertModerationState($english_node->getRevisionId(), $english_node->language()->getId(), 'draft');
// Revision 2 (fr)
$french_node = $english_node->addTranslation('fr', ['title' => 'French title']);
......@@ -90,6 +91,7 @@ public function testMultilingual() {
$french_node->save();
$this->assertTrue($french_node->isPublished());
$this->assertTrue($french_node->isDefaultRevision());
$this->assertModerationState($french_node->getRevisionId(), $french_node->language()->getId(), 'published');
// Revision 3 (fr)
$node = Node::load($english_node->id())->getTranslation('fr');
......@@ -97,6 +99,7 @@ public function testMultilingual() {
$node->save();
$this->assertFalse($node->isPublished());
$this->assertFalse($node->isDefaultRevision());
$this->assertModerationState($node->getRevisionId(), $node->language()->getId(), 'draft');
// Revision 4 (en)
$latest_revision = $this->entityTypeManager->getStorage('node')->loadRevision(3);
......@@ -104,6 +107,36 @@ public function testMultilingual() {
$latest_revision->save();
$this->assertFalse($latest_revision->isPublished());
$this->assertFalse($latest_revision->isDefaultRevision());
$this->assertModerationState($latest_revision->getRevisionId(), $latest_revision->language()->getId(), 'draft');
}
/**
* Verifies the expected moderation state revision exists.
*
* @param int $revision_id
* The revision ID of the host entity.
* @param string $langcode
* The language code of the host entity to check.
* @param string $expected_state
* The state the content moderation state revision should be in.
* @param string $expected_workflow
* The workflow the content moderation state revision should be using.
*/
protected function assertModerationState($revision_id, $langcode, $expected_state, $expected_workflow = 'editorial') {
$moderation_state_storage = $this->entityTypeManager->getStorage('content_moderation_state');
$query = $moderation_state_storage->getQuery();
$results = $query->allRevisions()
->condition('content_entity_revision_id', $revision_id)
->condition('langcode', $langcode)
->execute();
$this->assertCount(1, $results);
$moderation_state = $moderation_state_storage
->loadRevision(key($results))
->getTranslation($langcode);
$this->assertEquals($expected_state, $moderation_state->get('moderation_state')->value);
$this->assertEquals($expected_workflow, $moderation_state->get('workflow')->target_id);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment