Skip to content
Snippets Groups Projects
Commit b53de59a authored by Jess's avatar Jess
Browse files

Revert "Issue #2828438 by Adita, Sam152, rachel_norfolk, timmillwood,...

Revert "Issue #2828438 by Adita, Sam152, rachel_norfolk, timmillwood, jp.stacey: Exception when adding tab to a node managed by content moderation"

This reverts commit debf5fcc.
parent debf5fcc
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -2,8 +2,6 @@
namespace Drupal\content_moderation\Plugin\Menu;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Menu\LocalTaskDefault;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Routing\RouteMatchInterface;
......@@ -27,9 +25,9 @@ class EditTab extends LocalTaskDefault implements ContainerFactoryPluginInterfac
protected $moderationInfo;
/**
* The entity if determinable from the route or FALSE.
* The entity.
*
* @var \Drupal\Core\Entity\ContentEntityInterface|FALSE
* @var \Drupal\Core\Entity\ContentEntityInterface
*/
protected $entity;
......@@ -71,8 +69,8 @@ public static function create(ContainerInterface $container, array $configuratio
* {@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;
// Override the node here with the latest revision.
$this->entity = $route_match->getParameter($this->pluginDefinition['entity_type_id']);
return parent::getRouteParameters($route_match);
}
......@@ -80,8 +78,8 @@ public function getRouteParameters(RouteMatchInterface $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)) {
if (!$this->moderationInfo->isModeratedEntity($this->entity)) {
// Moderation isn't enabled.
return parent::getTitle();
}
......@@ -98,10 +96,8 @@ public function getCacheTags() {
// @todo https://www.drupal.org/node/2779933 write a test for this.
$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();
}
$tags = array_merge($tags, $this->entity->getCacheTags());
$tags[] = $this->entity->getEntityType()->getBundleEntityType() . ':' . $this->entity->bundle();
return $tags;
}
......
name: 'Content moderation test local task'
type: module
description: 'Provides a local task for testing.'
package: Testing
version: VERSION
core: 8.x
dependencies:
- content_moderation
- node
entity.node.test_local_task_without_upcast_node:
route_name: entity.node.test_local_task_without_upcast_node
base_route: entity.node.canonical
title: 'Task Without Upcast Node'
entity.node.test_local_task_without_upcast_node:
path: '/node/{node}/task-without-upcast-node'
defaults:
_title: 'Page Without Upcast Node'
_controller: '\Drupal\content_moderation_test_local_task\Controller\TestLocalTaskController::methodWithoutUpcastNode'
requirements:
_access: 'TRUE'
<?php
namespace Drupal\content_moderation_test_local_task\Controller;
/**
* A test controller.
*/
class TestLocalTaskController {
/**
* A method which does not hint the node parameter to avoid upcasting.
*/
public function methodWithoutUpcastNode($node) {
return ['#markup' => 'It works!'];
}
}
<?php
namespace Drupal\Tests\content_moderation\Functional;
use Drupal\simpletest\ContentTypeCreationTrait;
use Drupal\simpletest\NodeCreationTrait;
use Drupal\Tests\BrowserTestBase;
/**
* Test the content moderation local task.
*
* @group content_moderation
*/
class LocalTaskTest extends BrowserTestBase {
use ContentTypeCreationTrait;
use NodeCreationTrait;
/**
* {@inheritdoc}
*/
public static $modules = [
'content_moderation_test_local_task',
'content_moderation',
'block',
];
/**
* A test node.
*
* @var \Drupal\node\NodeInterface
*/
protected $testNode;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalPlaceBlock('local_tasks_block', ['id' => 'tabs_block']);
$this->drupalLogin($this->createUser(['bypass node access']));
$node_type = $this->createContentType();
$node_type
->setThirdPartySetting('content_moderation', 'enabled', TRUE)
->save();
$this->testNode = $this->createNode([
'type' => $node_type->id(),
'moderation_state' => 'draft',
]);
}
/**
* Tests local tasks behave with content_moderation enabled.
*/
public function testLocalTasks() {
$this->drupalGet(sprintf('node/%s', $this->testNode->id()));
$this->assertTasks(TRUE);
$this->clickLink('Task Without Upcast Node');
$this->assertTasks(FALSE);
}
/**
* Assert the correct tasks appear.
*/
protected function assertTasks($with_upcast_node) {
$this->assertSession()->linkExists('View');
$this->assertSession()->linkExists('Task Without Upcast Node');
$this->assertSession()->linkExists($with_upcast_node ? 'Edit draft' : 'Edit');
$this->assertSession()->linkExists('Delete');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment