summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLee Rowlands2017-09-24 10:51:58 +1000
committerLee Rowlands2017-09-24 10:51:58 +1000
commitc9b30844be04f095009e48488aca805fc02a5b8f (patch)
treee8699e4916da47a4eae6f8b2e39b0a22beb8c00f
parent73bba855dc7b694c9b7719b7cb0154f776ee8e67 (diff)
Issue #2875896 by Sam152, timmillwood: EntityRevisionConverter isn't invoked if an entity definition doesn't explicitly set an "edit" form handler
-rw-r--r--core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php2
-rw-r--r--core/modules/content_moderation/tests/src/Kernel/EntityRevisionConverterTest.php56
2 files changed, 50 insertions, 8 deletions
diff --git a/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php b/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php
index 561c0c0..8e7e361 100644
--- a/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php
+++ b/core/modules/content_moderation/src/ParamConverter/EntityRevisionConverter.php
@@ -75,7 +75,7 @@ class EntityRevisionConverter extends EntityConverter {
return FALSE;
}
$entity_type = $this->entityManager->getDefinition($entity_type_id);
- return $operation == 'edit' && $entity_type && $entity_type->isRevisionable();
+ return in_array($operation, ['default', 'edit']) && $entity_type && $entity_type->isRevisionable();
}
}
diff --git a/core/modules/content_moderation/tests/src/Kernel/EntityRevisionConverterTest.php b/core/modules/content_moderation/tests/src/Kernel/EntityRevisionConverterTest.php
index 6f209d1..3deaffa 100644
--- a/core/modules/content_moderation/tests/src/Kernel/EntityRevisionConverterTest.php
+++ b/core/modules/content_moderation/tests/src/Kernel/EntityRevisionConverterTest.php
@@ -3,6 +3,7 @@
namespace Drupal\Tests\content_moderation\Kernel;
use Drupal\entity_test\Entity\EntityTest;
+use Drupal\entity_test\Entity\EntityTestRev;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
@@ -24,19 +25,38 @@ class EntityRevisionConverterTest extends KernelTestBase {
];
/**
+ * The entity type manager.
+ *
+ * @var \Drupal\Core\Entity\EntityTypeManagerInterface
+ */
+ protected $entityTypeManager;
+
+ /**
+ * The router without access checks.
+ *
+ * @var \Symfony\Component\Routing\RouterInterface
+ */
+ protected $router;
+
+ /**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('entity_test');
+ $this->installEntitySchema('entity_test_rev');
$this->installEntitySchema('node');
$this->installEntitySchema('user');
$this->installEntitySchema('content_moderation_state');
$this->installSchema('system', 'router');
$this->installSchema('system', 'sequences');
$this->installSchema('node', 'node_access');
+ $this->installConfig(['content_moderation']);
\Drupal::service('router.builder')->rebuild();
+
+ $this->entityTypeManager = $this->container->get('entity_type.manager');
+ $this->router = $this->container->get('router.no_access_checks');
}
/**
@@ -49,19 +69,43 @@ class EntityRevisionConverterTest extends KernelTestBase {
$entity_test->save();
- /** @var \Symfony\Component\Routing\RouterInterface $router */
- $router = \Drupal::service('router.no_access_checks');
- $result = $router->match('/entity_test/' . $entity_test->id());
+ $result = $this->router->match('/entity_test/' . $entity_test->id());
$this->assertInstanceOf(EntityTest::class, $result['entity_test']);
$this->assertEquals($entity_test->getRevisionId(), $result['entity_test']->getRevisionId());
}
/**
+ * @covers ::applies
+ */
+ public function testConvertNoEditFormHandler() {
+ $workflow = Workflow::load('editorial');
+ $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_rev', 'entity_test_rev');
+ $workflow->save();
+
+ $entity_test_rev = EntityTestRev::create([
+ 'name' => 'Default Revision',
+ 'moderation_state' => 'published',
+ ]);
+ $entity_test_rev->save();
+
+ $entity_test_rev->name = 'Pending revision';
+ $entity_test_rev->moderation_state = 'draft';
+ $entity_test_rev->save();
+
+ // Ensure the entity type does not provide an explicit 'edit' form class.
+ $definition = $this->entityTypeManager->getDefinition($entity_test_rev->getEntityTypeId());
+ $this->assertNull($definition->getFormClass('edit'));
+
+ // Ensure the revision converter is invoked for the edit route.
+ $result = $this->router->match("/entity_test_rev/manage/{$entity_test_rev->id()}/edit");
+ $this->assertEquals($entity_test_rev->getRevisionId(), $result['entity_test_rev']->getRevisionId());
+ }
+
+ /**
* @covers ::convert
*/
public function testConvertWithRevisionableEntityType() {
- $this->installConfig(['content_moderation']);
$node_type = NodeType::create([
'type' => 'article',
]);
@@ -89,9 +133,7 @@ class EntityRevisionConverterTest extends KernelTestBase {
$node->save();
$revision_ids[] = $node->getRevisionId();
- /** @var \Symfony\Component\Routing\RouterInterface $router */
- $router = \Drupal::service('router.no_access_checks');
- $result = $router->match('/node/' . $node->id() . '/edit');
+ $result = $this->router->match('/node/' . $node->id() . '/edit');
$this->assertInstanceOf(Node::class, $result['node']);
$this->assertEquals($revision_ids[2], $result['node']->getRevisionId());