Skip to content
Snippets Groups Projects
Commit 9aaa6664 authored by catch's avatar catch
Browse files

Issue #3487482 by amateescu, catch, benjifisher, ekes, finn lewis, fabianx,...

Issue #3487482 by amateescu, catch, benjifisher, ekes, finn lewis, fabianx, larowlan: Creating a published moderated entity in a workspace shouldn't make it published in Live
parent dafc1fb9
No related branches found
No related tags found
15 merge requests!11197Issue #3506427 by eduardo morales alberti: Remove responsive_image.ajax from hook,!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!10786Issue #3490579 by shalini_jha, mstrelan: Add void return to all views...,!10210Issue #3487907: Drupal.displace() use getComputedStyle() for hidden chk.,!5423Draft: Resolve #3329907 "Test2",!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3478Issue #3337882: Deleted menus are not removed from content type config,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2062Issue #3246454: Add weekly granularity to views date sort,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!579Issue #2230909: Simple decimals fail to pass validation,!213Issue #2906496: Give Media a menu item under Content
......@@ -73,15 +73,19 @@ public function testModerationInWorkspace(): void {
$first_article = $this->drupalGetNodeByTitle('First article - published', TRUE);
$this->assertEquals('published', $first_article->moderation_state->value);
$this->assertTrue($first_article->isPublished());
$second_article = $this->drupalGetNodeByTitle('Second article - draft', TRUE);
$this->assertEquals('draft', $second_article->moderation_state->value);
$this->assertFalse($second_article->isPublished());
// Check that neither of them are visible in Live.
// Check that neither of them are published in Live.
$this->switchToLive();
$this->drupalGet('<front>');
$this->assertSession()->pageTextNotContains('First article');
$this->assertSession()->pageTextNotContains('Second article');
$first_article = $this->drupalGetNodeByTitle('First article - published', TRUE);
$this->assertFalse($first_article->isPublished());
$second_article = $this->drupalGetNodeByTitle('Second article - draft', TRUE);
$this->assertFalse($second_article->isPublished());
// Switch back to Stage.
$this->switchToWorkspace($stage);
......
......@@ -4,6 +4,7 @@
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\RevisionableInterface;
use Drupal\Core\Form\FormStateInterface;
......@@ -189,6 +190,7 @@ public function entityInsert(EntityInterface $entity) {
return;
}
assert($entity instanceof RevisionableInterface && $entity instanceof EntityPublishedInterface);
$this->workspaceAssociation->trackEntity($entity, $this->workspaceManager->getActiveWorkspace());
// When a published entity is created in a workspace, it should remain
......@@ -200,6 +202,12 @@ public function entityInsert(EntityInterface $entity) {
// entities where there is already a valid default revision for the live
// workspace.
if (isset($entity->_initialPublished)) {
// Ensure that the default revision of an entity saved in a workspace is
// unpublished.
if ($entity->isPublished()) {
throw new \RuntimeException('The default revision of an entity created in a workspace cannot be published.');
}
$entity->setPublished();
$entity->isDefaultRevision(FALSE);
$entity->save();
......
......@@ -14,6 +14,13 @@ function workspaces_module_implements_alter(&$implementations, $hook): void {
if ($hook === 'entity_presave') {
$implementation = $implementations['workspaces'];
$implementations = ['workspaces' => $implementation] + $implementations;
// Move Content Moderation's implementation before Workspaces, so we can
// alter the publishing status for the default revision.
if (isset($implementations['content_moderation'])) {
$implementation = $implementations['content_moderation'];
$implementations = ['content_moderation' => $implementation] + $implementations;
}
}
// Move our 'hook_entity_insert' implementation at the end to ensure that
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment