Revert "Issue #2856967 by yongt9412, Sam152: Allow admins to select a default starting moderation state"

This reverts commit a6b0f1de89.
8.7.x
Lee Rowlands 2018-09-21 10:29:52 +10:00
parent da2a2d28e0
commit 6b663aa312
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
10 changed files with 6 additions and 183 deletions

View File

@ -33,6 +33,3 @@ workflow.type_settings.content_moderation:
sequence:
type: string
label: 'Bundle ID'
default_moderation_state:
type: string
label: 'Default moderation state'

View File

@ -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;
}

View File

@ -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;
});
}

View File

@ -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.
}
}

View File

@ -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();
}
}

View File

@ -1,56 +0,0 @@
<?php
namespace Drupal\Tests\content_moderation\Functional;
/**
* Tests setting a custom default moderation state.
*
* @group content_moderation
*/
class DefaultModerationStateTest extends ModerationStateTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->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);
}
}

View File

@ -1,41 +0,0 @@
<?php
namespace Drupal\Tests\content_moderation\Functional;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
use Drupal\workflows\Entity\Workflow;
/**
* Tests the upgrade path for updating the 'default_moderation_state' setting.
*
* @group Update
* @group legacy
*
* @see content_moderation_post_update_set_default_moderation_state()
*/
class DefaultModerationStateUpdateTest extends UpdatePathTestBase {
/**
* {@inheritdoc}
*/
protected function setDatabaseDumpFiles() {
$this->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']);
}
}

View File

@ -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);
}
}

View File

@ -65,4 +65,3 @@ type_settings:
- article
- page
- recipe
default_moderation_state: draft

View File

@ -57,4 +57,3 @@ type_settings:
- draft
- published
entity_types: { }
default_moderation_state: draft