Loading core/modules/content_moderation/src/Entity/Handler/BlockContentModerationHandler.php +11 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\content_moderation\Entity\Handler; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Form\FormStateInterface; /** Loading Loading @@ -29,4 +30,14 @@ public function enforceRevisionsBundleFormAlter(array &$form, FormStateInterface $form['revision']['#description'] = $this->t('Revisions must be required when moderation is enabled.'); } /** * {@inheritdoc} */ public function isModeratedEntity(ContentEntityInterface $entity) { // Only reusable blocks can be moderated individually. Non-reusable or // inline blocks are moderated as part of the entity they are a composite // of. return $entity->isReusable(); } } core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php +8 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,14 @@ public static function createInstance(ContainerInterface $container, EntityTypeI return new static(); } /** * {@inheritdoc} */ public function isModeratedEntity(ContentEntityInterface $entity) { // Moderate all entities included in the moderation workflow by default. return TRUE; } /** * {@inheritdoc} */ Loading core/modules/content_moderation/src/Entity/Handler/ModerationHandlerInterface.php +23 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,29 @@ */ interface ModerationHandlerInterface { /** * Determines if an entity should be moderated. * * At the workflow level, moderation is enabled or disabled for entire entity * types or bundles. After a bundle has been enabled, there maybe be further * decisions each entity type may make to evaluate if a given entity is * appropriate to be included in a moderation workflow. The handler is only * consulted after the user has configured the associated entity type and * bundle to be included in a moderation workflow. * * Returning FALSE will remove the moderation state field widget from the * associated entity form and opt out of all moderation related entity * semantics, such as creating new revisions and changing the publishing * status of a revision. * * @param \Drupal\Core\Entity\ContentEntityInterface $entity * The entity we may be moderating. * * @return bool * TRUE if this entity should be moderated, FALSE otherwise. */ public function isModeratedEntity(ContentEntityInterface $entity); /** * Operates on moderated content entities preSave(). * Loading core/modules/content_moderation/src/ModerationInformation.php +4 −2 Original line number Diff line number Diff line Loading @@ -52,8 +52,10 @@ public function isModeratedEntity(EntityInterface $entity) { if (!$entity instanceof ContentEntityInterface) { return FALSE; } return $this->shouldModerateEntitiesOfBundle($entity->getEntityType(), $entity->bundle()); if (!$this->shouldModerateEntitiesOfBundle($entity->getEntityType(), $entity->bundle())) { return FALSE; } return $this->entityTypeManager->getHandler($entity->getEntityTypeId(), 'moderation')->isModeratedEntity($entity); } /** Loading core/modules/content_moderation/tests/src/Functional/LayoutBuilderContentModerationIntegrationTest.php +55 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\Tests\content_moderation\Functional; use Drupal\block_content\Entity\BlockContentType; use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay; use Drupal\Tests\BrowserTestBase; use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait; Loading @@ -24,6 +25,7 @@ class LayoutBuilderContentModerationIntegrationTest extends BrowserTestBase { 'node', 'content_moderation', 'menu_ui', 'block_content', ]; /** Loading @@ -41,10 +43,21 @@ protected function setUp(): void { // https://www.drupal.org/project/drupal/issues/2917777. $this->drupalPlaceBlock('local_tasks_block'); $workflow = $this->createEditorialWorkflow(); // Add a new bundle and add an editorial workflow. $this->createContentType(['type' => 'bundle_with_section_field']); $workflow = $this->createEditorialWorkflow(); $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'bundle_with_section_field'); // Add a new block content bundle to the editorial workflow. BlockContentType::create([ 'id' => 'basic', 'label' => 'Basic', 'revision' => 1, ])->save(); block_content_add_body_field('basic'); $workflow->getTypePlugin()->addEntityTypeAndBundle('block_content', 'basic'); $workflow->save(); // Enable layout overrides. Loading @@ -62,6 +75,7 @@ protected function setUp(): void { 'view latest version', 'use editorial transition create_new_draft', 'use editorial transition publish', 'create and edit custom blocks', ])); } Loading Loading @@ -138,4 +152,44 @@ public function testLayoutModeration() { $assert_session->pageTextNotContains('Powered by Drupal'); } /** * Test placing inline blocks that belong to a moderated custom block bundle. */ public function testModeratedInlineBlockBundles() { $page = $this->getSession()->getPage(); $assert_session = $this->assertSession(); $node = $this->createNode([ 'type' => 'bundle_with_section_field', 'title' => 'The first node title', 'moderation_state' => 'published', ]); $this->drupalGet("node/{$node->id()}/layout"); $page->clickLink('Add block'); $this->clickLink('Create custom block'); $assert_session->fieldNotExists('settings[block_form][moderation_state][0][state]'); $this->submitForm([ 'settings[label]' => 'Test inline block', 'settings[block_form][body][0][value]' => 'Example block body', ], 'Add block'); // Save a draft of the page with the inline block and ensure the drafted // content appears on the latest version page. $this->assertSession()->pageTextContains('Example block body'); $this->submitForm([ 'moderation_state[0][state]' => 'draft', ], 'Save layout'); $assert_session->pageTextContains('The layout override has been saved.'); $assert_session->pageTextContains('Example block body'); // Publish the draft of the page ensure the draft inline block content // apears on the published page. $this->submitForm([ 'new_state' => 'published', ], 'Apply'); $assert_session->pageTextContains('The moderation state has been updated.'); $assert_session->pageTextContains('Example block body'); } } Loading
core/modules/content_moderation/src/Entity/Handler/BlockContentModerationHandler.php +11 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\content_moderation\Entity\Handler; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Form\FormStateInterface; /** Loading Loading @@ -29,4 +30,14 @@ public function enforceRevisionsBundleFormAlter(array &$form, FormStateInterface $form['revision']['#description'] = $this->t('Revisions must be required when moderation is enabled.'); } /** * {@inheritdoc} */ public function isModeratedEntity(ContentEntityInterface $entity) { // Only reusable blocks can be moderated individually. Non-reusable or // inline blocks are moderated as part of the entity they are a composite // of. return $entity->isReusable(); } }
core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php +8 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,14 @@ public static function createInstance(ContainerInterface $container, EntityTypeI return new static(); } /** * {@inheritdoc} */ public function isModeratedEntity(ContentEntityInterface $entity) { // Moderate all entities included in the moderation workflow by default. return TRUE; } /** * {@inheritdoc} */ Loading
core/modules/content_moderation/src/Entity/Handler/ModerationHandlerInterface.php +23 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,29 @@ */ interface ModerationHandlerInterface { /** * Determines if an entity should be moderated. * * At the workflow level, moderation is enabled or disabled for entire entity * types or bundles. After a bundle has been enabled, there maybe be further * decisions each entity type may make to evaluate if a given entity is * appropriate to be included in a moderation workflow. The handler is only * consulted after the user has configured the associated entity type and * bundle to be included in a moderation workflow. * * Returning FALSE will remove the moderation state field widget from the * associated entity form and opt out of all moderation related entity * semantics, such as creating new revisions and changing the publishing * status of a revision. * * @param \Drupal\Core\Entity\ContentEntityInterface $entity * The entity we may be moderating. * * @return bool * TRUE if this entity should be moderated, FALSE otherwise. */ public function isModeratedEntity(ContentEntityInterface $entity); /** * Operates on moderated content entities preSave(). * Loading
core/modules/content_moderation/src/ModerationInformation.php +4 −2 Original line number Diff line number Diff line Loading @@ -52,8 +52,10 @@ public function isModeratedEntity(EntityInterface $entity) { if (!$entity instanceof ContentEntityInterface) { return FALSE; } return $this->shouldModerateEntitiesOfBundle($entity->getEntityType(), $entity->bundle()); if (!$this->shouldModerateEntitiesOfBundle($entity->getEntityType(), $entity->bundle())) { return FALSE; } return $this->entityTypeManager->getHandler($entity->getEntityTypeId(), 'moderation')->isModeratedEntity($entity); } /** Loading
core/modules/content_moderation/tests/src/Functional/LayoutBuilderContentModerationIntegrationTest.php +55 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\Tests\content_moderation\Functional; use Drupal\block_content\Entity\BlockContentType; use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay; use Drupal\Tests\BrowserTestBase; use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait; Loading @@ -24,6 +25,7 @@ class LayoutBuilderContentModerationIntegrationTest extends BrowserTestBase { 'node', 'content_moderation', 'menu_ui', 'block_content', ]; /** Loading @@ -41,10 +43,21 @@ protected function setUp(): void { // https://www.drupal.org/project/drupal/issues/2917777. $this->drupalPlaceBlock('local_tasks_block'); $workflow = $this->createEditorialWorkflow(); // Add a new bundle and add an editorial workflow. $this->createContentType(['type' => 'bundle_with_section_field']); $workflow = $this->createEditorialWorkflow(); $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'bundle_with_section_field'); // Add a new block content bundle to the editorial workflow. BlockContentType::create([ 'id' => 'basic', 'label' => 'Basic', 'revision' => 1, ])->save(); block_content_add_body_field('basic'); $workflow->getTypePlugin()->addEntityTypeAndBundle('block_content', 'basic'); $workflow->save(); // Enable layout overrides. Loading @@ -62,6 +75,7 @@ protected function setUp(): void { 'view latest version', 'use editorial transition create_new_draft', 'use editorial transition publish', 'create and edit custom blocks', ])); } Loading Loading @@ -138,4 +152,44 @@ public function testLayoutModeration() { $assert_session->pageTextNotContains('Powered by Drupal'); } /** * Test placing inline blocks that belong to a moderated custom block bundle. */ public function testModeratedInlineBlockBundles() { $page = $this->getSession()->getPage(); $assert_session = $this->assertSession(); $node = $this->createNode([ 'type' => 'bundle_with_section_field', 'title' => 'The first node title', 'moderation_state' => 'published', ]); $this->drupalGet("node/{$node->id()}/layout"); $page->clickLink('Add block'); $this->clickLink('Create custom block'); $assert_session->fieldNotExists('settings[block_form][moderation_state][0][state]'); $this->submitForm([ 'settings[label]' => 'Test inline block', 'settings[block_form][body][0][value]' => 'Example block body', ], 'Add block'); // Save a draft of the page with the inline block and ensure the drafted // content appears on the latest version page. $this->assertSession()->pageTextContains('Example block body'); $this->submitForm([ 'moderation_state[0][state]' => 'draft', ], 'Save layout'); $assert_session->pageTextContains('The layout override has been saved.'); $assert_session->pageTextContains('Example block body'); // Publish the draft of the page ensure the draft inline block content // apears on the published page. $this->submitForm([ 'new_state' => 'published', ], 'Apply'); $assert_session->pageTextContains('The moderation state has been updated.'); $assert_session->pageTextContains('Example block body'); } }