Commit f589b880 authored by xjm's avatar xjm

Issue #2856917 by amateescu, kriboogh: Moderating an entity that uses a...

Issue #2856917 by amateescu, kriboogh: Moderating an entity that uses a special language (e.g. LANGCODE_NOT_SPECIFIED) throws exception
parent 42e575a2
......@@ -179,6 +179,9 @@ protected function updateOrCreateFromEntity(EntityInterface $entity) {
$content_moderation_state = $storage->create([
'content_entity_type_id' => $entity_type_id,
'content_entity_id' => $entity_id,
// Make sure that the moderation state entity has the same language code
// as the moderated entity.
'langcode' => $entity->language()->getId(),
]);
$content_moderation_state->workflow->target_id = $workflow->id();
}
......
......@@ -5,7 +5,9 @@
use Drupal\content_moderation\Entity\ContentModerationState;
use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Language\LanguageInterface;
use Drupal\entity_test\Entity\EntityTestBundle;
use Drupal\entity_test\Entity\EntityTestRev;
use Drupal\entity_test\Entity\EntityTestWithBundle;
use Drupal\Core\Entity\EntityInterface;
use Drupal\KernelTests\KernelTestBase;
......@@ -327,6 +329,27 @@ public function testMultilingualModeration() {
$this->assertEquals(6, $english_node->getRevisionId());
}
/**
* Tests that entities with special languages can be moderated.
*/
public function testModerationWithSpecialLanguages() {
$workflow = Workflow::load('editorial');
$workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_rev', 'entity_test_rev');
$workflow->save();
// Create a test entity.
$entity = EntityTestRev::create([
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
]);
$entity->save();
$this->assertEquals('draft', $entity->moderation_state->value);
$entity->moderation_state->value = 'published';
$entity->save();
$this->assertEquals('published', EntityTestRev::load($entity->id())->moderation_state->value);
}
/**
* Tests that a non-translatable entity type with a langcode can be moderated.
*/
......
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