Unverified Commit e145f2a5 authored by larowlan's avatar larowlan

Issue #2932551 by jeqq: Error when calling...

Issue #2932551 by jeqq: Error when calling ModerationStateFieldItemList::updateModeratedEntity() if the entity doesn't have workflow
parent f9548751
......@@ -153,7 +153,7 @@ protected function updateModeratedEntity($moderation_state_id) {
// Change the entity's default revision flag and the publishing status only
// if the new workflow state is a valid one.
if ($workflow->getTypePlugin()->hasState($moderation_state_id)) {
if ($workflow && $workflow->getTypePlugin()->hasState($moderation_state_id)) {
/** @var \Drupal\content_moderation\ContentModerationState $current_state */
$current_state = $workflow->getTypePlugin()->getState($moderation_state_id);
......
......@@ -99,4 +99,29 @@ public function testModerationStateChanges() {
$this->assertFalse($this->testNode->isDefaultRevision());
}
/**
* Test updating the state for an entity without a workflow.
*/
public function testEntityWithNoWorkflow() {
$node_type = NodeType::create([
'type' => 'example_no_workflow',
]);
$node_type->save();
$test_node = Node::create([
'type' => 'example_no_workflow',
'title' => 'Test node with no workflow',
]);
$test_node->save();
/** @var \Drupal\content_moderation\ModerationInformationInterface $content_moderation_info */
$content_moderation_info = \Drupal::service('content_moderation.moderation_information');
$workflow = $content_moderation_info->getWorkflowForEntity($test_node);
$this->assertNull($workflow);
$this->assertTrue($test_node->isPublished());
$test_node->moderation_state->setValue('draft');
// The entity is still published because there is not a workflow.
$this->assertTrue($test_node->isPublished());
}
}
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