From 6b663aa3129aa9916b7066a386ef99f477db566c Mon Sep 17 00:00:00 2001 From: Lee Rowlands Date: Fri, 21 Sep 2018 10:29:52 +1000 Subject: [PATCH] Revert "Issue #2856967 by yongt9412, Sam152: Allow admins to select a default starting moderation state" This reverts commit a6b0f1de89c8bab40193a48f6005f831408ec70d. --- .../schema/content_moderation.schema.yml | 3 - .../content_moderation.module | 9 --- .../content_moderation.post_update.php | 16 ------ .../Form/ContentModerationConfigureForm.php | 21 +------ .../Plugin/WorkflowType/ContentModeration.php | 8 +-- .../Functional/DefaultModerationStateTest.php | 56 ------------------- .../DefaultModerationStateUpdateTest.php | 41 -------------- .../ModerationStateFieldItemListTest.php | 33 ----------- .../install/workflows.workflow.editorial.yml | 1 - .../optional/workflows.workflow.editorial.yml | 1 - 10 files changed, 6 insertions(+), 183 deletions(-) delete mode 100644 core/modules/content_moderation/tests/src/Functional/DefaultModerationStateTest.php delete mode 100644 core/modules/content_moderation/tests/src/Functional/DefaultModerationStateUpdateTest.php diff --git a/core/modules/content_moderation/config/schema/content_moderation.schema.yml b/core/modules/content_moderation/config/schema/content_moderation.schema.yml index 7b14efbe4927..d48ffe439f8d 100644 --- a/core/modules/content_moderation/config/schema/content_moderation.schema.yml +++ b/core/modules/content_moderation/config/schema/content_moderation.schema.yml @@ -33,6 +33,3 @@ workflow.type_settings.content_moderation: sequence: type: string label: 'Bundle ID' - default_moderation_state: - type: string - label: 'Default moderation state' diff --git a/core/modules/content_moderation/content_moderation.module b/core/modules/content_moderation/content_moderation.module index 347cbaf8aa51..3481c243e186 100644 --- a/core/modules/content_moderation/content_moderation.module +++ b/core/modules/content_moderation/content_moderation.module @@ -207,15 +207,6 @@ function content_moderation_entity_access(EntityInterface $entity, $operation, A } } - // Do not allow users to delete the state that is configured as the default - // state for the workflow. - if ($entity instanceof WorkflowInterface) { - $configuration = $entity->getTypePlugin()->getConfiguration(); - if (!empty($configuration['default_moderation_state']) && $operation === sprintf('delete-state:%s', $configuration['default_moderation_state'])) { - return AccessResult::forbidden()->addCacheableDependency($entity); - } - } - return $access_result; } diff --git a/core/modules/content_moderation/content_moderation.post_update.php b/core/modules/content_moderation/content_moderation.post_update.php index 49f8fd73fcf1..ff5a28a9d3b3 100644 --- a/core/modules/content_moderation/content_moderation.post_update.php +++ b/core/modules/content_moderation/content_moderation.post_update.php @@ -5,7 +5,6 @@ * Post update functions for the Content Moderation module. */ -use Drupal\Core\Config\Entity\ConfigEntityUpdater; use Drupal\Core\Site\Settings; use Drupal\workflows\Entity\Workflow; @@ -95,18 +94,3 @@ function content_moderation_post_update_update_cms_default_revisions(&$sandbox) $sandbox['offset'] += $sandbox['limit']; } - -/** - * Set the default moderation state for new content to 'draft'. - */ -function content_moderation_post_update_set_default_moderation_state(&$sandbox) { - \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'workflow', function (Workflow $workflow) { - if ($workflow->get('type') === 'content_moderation') { - $configuration = $workflow->getTypePlugin()->getConfiguration(); - $configuration['default_moderation_state'] = 'draft'; - $workflow->getTypePlugin()->setConfiguration($configuration); - return TRUE; - } - return FALSE; - }); -} diff --git a/core/modules/content_moderation/src/Form/ContentModerationConfigureForm.php b/core/modules/content_moderation/src/Form/ContentModerationConfigureForm.php index f43451ec63df..274b9f8e3784 100644 --- a/core/modules/content_moderation/src/Form/ContentModerationConfigureForm.php +++ b/core/modules/content_moderation/src/Form/ContentModerationConfigureForm.php @@ -10,7 +10,6 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Drupal\workflows\Plugin\WorkflowTypeConfigureFormBase; -use Drupal\workflows\State; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -129,21 +128,6 @@ class ContentModerationConfigureForm extends WorkflowTypeConfigureFormBase imple ], ]; } - - $workflow_type_configuration = $this->workflowType->getConfiguration(); - $form['workflow_settings'] = [ - '#type' => 'details', - '#title' => $this->t('Workflow Settings'), - '#open' => TRUE, - ]; - $form['workflow_settings']['default_moderation_state'] = [ - '#title' => $this->t('Default moderation state'), - '#type' => 'select', - '#required' => TRUE, - '#options' => array_map([State::class, 'labelCallback'], $this->workflowType->getStates()), - '#description' => $this->t('Select the state that new content will be assigned. This state will appear as the default in content forms and the available target states will be based on the transitions available from this state.'), - '#default_value' => isset($workflow_type_configuration['default_moderation_state']) ? $workflow_type_configuration['default_moderation_state'] : 'draft', - ]; return $form; } @@ -151,9 +135,8 @@ class ContentModerationConfigureForm extends WorkflowTypeConfigureFormBase imple * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - $configuration = $this->workflowType->getConfiguration(); - $configuration['default_moderation_state'] = $form_state->getValue(['workflow_settings', 'default_moderation_state']); - $this->workflowType->setConfiguration($configuration); + // Configuration is updated from modal windows launched from this form, no + // need to change any configuration here. } } diff --git a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php index 5182c6b3fd9a..358314a4cadf 100644 --- a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php +++ b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php @@ -306,11 +306,11 @@ class ContentModeration extends WorkflowTypeBase implements ContentModerationInt if (!($entity instanceof ContentEntityInterface)) { throw new \InvalidArgumentException('A content entity object must be supplied.'); } - if ($entity instanceof EntityPublishedInterface && !$entity->isNew()) { - return $this->getState($entity->isPublished() ? 'published' : 'draft'); + if ($entity instanceof EntityPublishedInterface) { + return $this->getState($entity->isPublished() && !$entity->isNew() ? 'published' : 'draft'); } - - return $this->getState(!empty($this->configuration['default_moderation_state']) ? $this->configuration['default_moderation_state'] : 'draft'); + // Workflows determines the initial state for non-publishable entities. + return parent::getInitialState(); } } diff --git a/core/modules/content_moderation/tests/src/Functional/DefaultModerationStateTest.php b/core/modules/content_moderation/tests/src/Functional/DefaultModerationStateTest.php deleted file mode 100644 index f5f6a5c004aa..000000000000 --- a/core/modules/content_moderation/tests/src/Functional/DefaultModerationStateTest.php +++ /dev/null @@ -1,56 +0,0 @@ -drupalLogin($this->adminUser); - $this->createContentTypeFromUi('Moderated content', 'moderated_content', TRUE); - $this->grantUserPermissionToCreateContentOfType($this->adminUser, 'moderated_content'); - } - - /** - * Test a workflow with a default moderation state set. - */ - public function testPublishedDefaultState() { - // Set the default moderation state to be "published". - $this->drupalPostForm('admin/config/workflow/workflows/manage/' . $this->workflow->id(), [ - 'type_settings[workflow_settings][default_moderation_state]' => 'published', - ], 'Save'); - - $this->drupalGet('node/add/moderated_content'); - $this->assertEquals('published', $this->assertSession()->selectExists('moderation_state[0][state]')->getValue()); - $this->submitForm([ - 'title[0][value]' => 'moderated content', - ], 'Save'); - - $node = $this->getNodeByTitle('moderated content'); - $this->assertEquals('published', $node->moderation_state->value); - } - - /** - * Test access to deleting the default state. - */ - public function testDeleteDefaultStateAccess() { - $this->drupalGet('admin/config/workflow/workflows/manage/editorial/state/archived/delete'); - $this->assertSession()->statusCodeEquals(200); - - $this->drupalPostForm('admin/config/workflow/workflows/manage/' . $this->workflow->id(), [ - 'type_settings[workflow_settings][default_moderation_state]' => 'archived', - ], 'Save'); - - $this->drupalGet('admin/config/workflow/workflows/manage/editorial/state/archived/delete'); - $this->assertSession()->statusCodeEquals(403); - } - -} diff --git a/core/modules/content_moderation/tests/src/Functional/DefaultModerationStateUpdateTest.php b/core/modules/content_moderation/tests/src/Functional/DefaultModerationStateUpdateTest.php deleted file mode 100644 index a2e80d4f88de..000000000000 --- a/core/modules/content_moderation/tests/src/Functional/DefaultModerationStateUpdateTest.php +++ /dev/null @@ -1,41 +0,0 @@ -databaseDumpFiles = [ - __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.4.0.bare.standard.php.gz', - __DIR__ . '/../../fixtures/update/drupal-8.4.0-content_moderation_installed.php', - ]; - } - - /** - * Tests updating the default moderation state setting. - */ - public function testUpdateDefaultModerationState() { - $workflow = Workflow::load('editorial'); - $this->assertFalse(isset($workflow->getTypePlugin()->getConfiguration()['default_moderation_state'])); - - $this->runUpdates(); - - $workflow = Workflow::load('editorial'); - $this->assertEquals('draft', $workflow->getTypePlugin()->getConfiguration()['default_moderation_state']); - } - -} diff --git a/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php b/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php index 844e77d93082..af0bb4fd7d6d 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php @@ -6,7 +6,6 @@ use Drupal\KernelTests\KernelTestBase; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait; -use Drupal\workflows\Entity\Workflow; /** * @coversDefaultClass \Drupal\content_moderation\Plugin\Field\ModerationStateFieldItemList @@ -282,36 +281,4 @@ class ModerationStateFieldItemListTest extends KernelTestBase { ]; } - /** - * Test customising the default moderation state. - */ - public function testWorkflowCustomisedInitialState() { - $workflow = Workflow::load('editorial'); - $configuration = $workflow->getTypePlugin()->getConfiguration(); - - // Test a node for a workflow that hasn't been updated to include the - // 'default_moderation_state' setting. We must be backwards compatible with - // configuration that was exported before this change was introduced. - $this->assertFalse(isset($configuration['default_moderation_state'])); - $legacy_configuration_node = Node::create([ - 'title' => 'Test title', - 'type' => 'example', - ]); - $this->assertEquals('draft', $legacy_configuration_node->moderation_state->value); - $legacy_configuration_node->save(); - $this->assertEquals('draft', $legacy_configuration_node->moderation_state->value); - - $configuration['default_moderation_state'] = 'published'; - $workflow->getTypePlugin()->setConfiguration($configuration); - $workflow->save(); - - $updated_default_node = Node::create([ - 'title' => 'Test title', - 'type' => 'example', - ]); - $this->assertEquals('published', $updated_default_node->moderation_state->value); - $legacy_configuration_node->save(); - $this->assertEquals('published', $updated_default_node->moderation_state->value); - } - } diff --git a/core/profiles/demo_umami/config/install/workflows.workflow.editorial.yml b/core/profiles/demo_umami/config/install/workflows.workflow.editorial.yml index 601289de9442..9959410e1e68 100644 --- a/core/profiles/demo_umami/config/install/workflows.workflow.editorial.yml +++ b/core/profiles/demo_umami/config/install/workflows.workflow.editorial.yml @@ -65,4 +65,3 @@ type_settings: - article - page - recipe - default_moderation_state: draft diff --git a/core/profiles/standard/config/optional/workflows.workflow.editorial.yml b/core/profiles/standard/config/optional/workflows.workflow.editorial.yml index 0d1154b36e3c..52dbc27542da 100644 --- a/core/profiles/standard/config/optional/workflows.workflow.editorial.yml +++ b/core/profiles/standard/config/optional/workflows.workflow.editorial.yml @@ -57,4 +57,3 @@ type_settings: - draft - published entity_types: { } - default_moderation_state: draft