Unverified Commit c9b30844 authored by larowlan's avatar larowlan

Issue #2875896 by Sam152, timmillwood: EntityRevisionConverter isn't invoked...

Issue #2875896 by Sam152, timmillwood: EntityRevisionConverter isn't invoked if an entity definition doesn't explicitly set an "edit" form handler
parent 73bba855
......@@ -75,7 +75,7 @@ protected function isEditFormPage(Route $route) {
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();
}
}
......
......@@ -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;
......@@ -23,6 +24,20 @@ class EntityRevisionConverterTest extends KernelTestBase {
'workflows',
];
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The router without access checks.
*
* @var \Symfony\Component\Routing\RouterInterface
*/
protected $router;
/**
* {@inheritdoc}
*/
......@@ -30,13 +45,18 @@ 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 @@ public function testConvertNonRevisionableEntityType() {
$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 @@ public function testConvertWithRevisionableEntityType() {
$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());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment