From eee757d9be66f9d3cd9ac2a5b02ad32fddf6ef80 Mon Sep 17 00:00:00 2001 From: Gabor Hojtsy Date: Wed, 12 Apr 2017 09:30:32 +0200 Subject: [PATCH] Issue #2866656 by alexpott, yoroy, timmillwood: Clicking on "New Draft" tab allows you to archive the content --- .../content_moderation.module | 17 --- .../src/Plugin/Menu/EditTab.php | 105 ------------------ .../tests/src/Functional/LocalTaskTest.php | 96 ---------------- 3 files changed, 218 deletions(-) delete mode 100644 core/modules/content_moderation/src/Plugin/Menu/EditTab.php delete mode 100644 core/modules/content_moderation/tests/src/Functional/LocalTaskTest.php diff --git a/core/modules/content_moderation/content_moderation.module b/core/modules/content_moderation/content_moderation.module index 7345e931dcf..77d822be28a 100644 --- a/core/modules/content_moderation/content_moderation.module +++ b/core/modules/content_moderation/content_moderation.module @@ -10,7 +10,6 @@ use Drupal\content_moderation\EntityTypeInfo; use Drupal\content_moderation\ContentPreprocess; use Drupal\content_moderation\Plugin\Action\ModerationOptOutPublishNode; use Drupal\content_moderation\Plugin\Action\ModerationOptOutUnpublishNode; -use Drupal\content_moderation\Plugin\Menu\EditTab; use Drupal\Core\Access\AccessResult; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; @@ -99,22 +98,6 @@ function content_moderation_entity_update(EntityInterface $entity) { ->entityUpdate($entity); } -/** - * Implements hook_local_tasks_alter(). - */ -function content_moderation_local_tasks_alter(&$local_tasks) { - $content_entity_type_ids = array_keys(array_filter(\Drupal::entityTypeManager()->getDefinitions(), function (EntityTypeInterface $entity_type) { - return $entity_type->isRevisionable(); - })); - - foreach ($content_entity_type_ids as $content_entity_type_id) { - if (isset($local_tasks["entity.$content_entity_type_id.edit_form"])) { - $local_tasks["entity.$content_entity_type_id.edit_form"]['class'] = EditTab::class; - $local_tasks["entity.$content_entity_type_id.edit_form"]['entity_type_id'] = $content_entity_type_id; - } - } -} - /** * Implements hook_form_alter(). */ diff --git a/core/modules/content_moderation/src/Plugin/Menu/EditTab.php b/core/modules/content_moderation/src/Plugin/Menu/EditTab.php deleted file mode 100644 index b94a45976e3..00000000000 --- a/core/modules/content_moderation/src/Plugin/Menu/EditTab.php +++ /dev/null @@ -1,105 +0,0 @@ -stringTranslation = $string_translation; - $this->moderationInfo = $moderation_information; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('string_translation'), - $container->get('content_moderation.moderation_information') - ); - } - - /** - * {@inheritdoc} - */ - public function getRouteParameters(RouteMatchInterface $route_match) { - $entity_parameter = $route_match->getParameter($this->pluginDefinition['entity_type_id']); - $this->entity = $entity_parameter instanceof ContentEntityInterface ? $route_match->getParameter($this->pluginDefinition['entity_type_id']) : FALSE; - return parent::getRouteParameters($route_match); - } - - /** - * {@inheritdoc} - */ - public function getTitle() { - // If the entity couldn't be loaded or moderation isn't enabled. - if (!$this->entity || !$this->moderationInfo->isModeratedEntity($this->entity)) { - return parent::getTitle(); - } - - return $this->moderationInfo->isLiveRevision($this->entity) - ? $this->t('New draft') - : $this->t('Edit draft'); - } - - /** - * {@inheritdoc} - */ - public function getCacheTags() { - $tags = parent::getCacheTags(); - // Tab changes if node or node-type is modified. - if ($this->entity) { - $tags = array_merge($tags, $this->entity->getCacheTags()); - $tags[] = $this->entity->getEntityType()->getBundleEntityType() . ':' . $this->entity->bundle(); - } - return $tags; - } - -} diff --git a/core/modules/content_moderation/tests/src/Functional/LocalTaskTest.php b/core/modules/content_moderation/tests/src/Functional/LocalTaskTest.php deleted file mode 100644 index 586a91a4918..00000000000 --- a/core/modules/content_moderation/tests/src/Functional/LocalTaskTest.php +++ /dev/null @@ -1,96 +0,0 @@ -drupalPlaceBlock('local_tasks_block', ['id' => 'tabs_block']); - $this->drupalLogin($this->createUser(['bypass node access'])); - - $node_type = $this->createContentType([ - 'type' => 'test_content_type', - ]); - - // Now enable moderation for subsequent nodes. - $workflow = Workflow::load('editorial'); - $workflow->getTypePlugin()->addEntityTypeAndBundle('node', $node_type->id()); - $workflow->save(); - - $this->testNode = $this->createNode([ - 'type' => $node_type->id(), - 'moderation_state' => 'draft', - ]); - } - - /** - * Tests local tasks behave with content_moderation enabled. - */ - public function testLocalTasks() { - // The default state is a draft. - $this->drupalGet(sprintf('node/%s', $this->testNode->id())); - $this->assertTasks('Edit draft'); - - // When published as the live revision, the label changes. - $this->testNode->moderation_state = 'published'; - $this->testNode->save(); - $this->drupalGet(sprintf('node/%s', $this->testNode->id())); - $this->assertTasks('New draft'); - - $tags = $this->drupalGetHeader('X-Drupal-Cache-Tags'); - $this->assertContains('node:1', $tags); - $this->assertContains('node_type:test_content_type', $tags); - - // Without an upcast node, the state cannot be determined. - $this->clickLink('Task Without Upcast Node'); - $this->assertTasks('Edit'); - } - - /** - * Assert the correct tasks appear. - * - * @param string $edit_tab_label - * The edit tab label to assert. - */ - protected function assertTasks($edit_tab_label) { - $this->assertSession()->linkExists('View'); - $this->assertSession()->linkExists('Task Without Upcast Node'); - $this->assertSession()->linkExists($edit_tab_label); - $this->assertSession()->linkExists('Delete'); - } - -}