Skip to content
Snippets Groups Projects
Verified Commit 311c787f authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3418298 by Akhil Babu, Kanchan Bhogade: Improve the exception message...

Issue #3418298 by Akhil Babu, Kanchan Bhogade: Improve the exception message when an entity form class does not exist

(cherry picked from commit 59f38cc3)
parent cfacbed7
No related branches found
No related tags found
9 merge requests!8376Drupal views: adding more granularity to the ‘use ajax’ functionality,!8300Issue #3443586 View area displays even when parent view has no results.,!7567Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7565Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7509Change label "Block description" to "Block type",!7344Issue #3292350 by O'Briat, KlemenDEV, hswong3i, smustgrave, quietone: Update...,!6922Issue #3412959 by quietone, smustgrave, longwave: Fix 12 'un' words,!6848Issue #3417553 by longwave: Remove withConsecutive() in CacheCollectorTest,!6720Revert "Issue #3358581 by pfrenssen, _tarik_, a.dmitriiev, smustgrave:...
Pipeline #98170 canceled
......@@ -204,7 +204,11 @@ public function getListBuilder($entity_type_id) {
*/
public function getFormObject($entity_type_id, $operation) {
if (!$class = $this->getDefinition($entity_type_id, TRUE)->getFormClass($operation)) {
throw new InvalidPluginDefinitionException($entity_type_id, sprintf('The "%s" entity type did not specify a "%s" form class.', $entity_type_id, $operation));
$handlers = $this->getDefinition($entity_type_id, TRUE)->getHandlerClasses();
if (!isset($handlers['form'][$operation])) {
throw new InvalidPluginDefinitionException($entity_type_id, sprintf('The "%s" entity type did not specify a "%s" form class.', $entity_type_id, $operation));
}
throw new InvalidPluginDefinitionException($entity_type_id, sprintf('The "%s" form handler of the "%s" entity type specifies a non-existent class "%s".', $operation, $entity_type_id, $handlers['form'][$operation]));
}
$form_object = $this->classResolver->getInstanceFromDefinition($class);
......
......@@ -246,18 +246,52 @@ public function testGetFormObject() {
$this->assertEquals('yellow', $banana_form->color);
}
/**
* Provides test data for testGetFormObjectInvalidOperation().
*
* @return array
* Test data.
*/
public function provideFormObjectInvalidOperationData(): array {
return [
'missing_form_handler' => [
'test_entity_type',
'edit',
'',
'The "test_entity_type" entity type did not specify a "edit" form class.',
],
'missing_form_handler_class' => [
'test_entity_type',
'edit',
'Drupal\test_entity_type\Form\NonExistingClass',
'The "edit" form handler of the "test_entity_type" entity type specifies a non-existent class "Drupal\test_entity_type\Form\NonExistingClass".',
],
];
}
/**
* Tests the getFormObject() method with an invalid operation.
*
* @covers ::getFormObject
*
* @dataProvider provideFormObjectInvalidOperationData
*/
public function testGetFormObjectInvalidOperation() {
public function testGetFormObjectInvalidOperation(string $entity_type_id, string $operation, string $form_class, string $exception_message): void {
$entity = $this->prophesize(EntityTypeInterface::class);
$entity->getFormClass('edit')->willReturn('');
$this->setUpEntityTypeDefinitions(['test_entity_type' => $entity]);
$entity->getFormClass($operation)->willReturn(NULL);
if (!$form_class) {
$entity->getHandlerClasses()->willReturn([]);
}
else {
$entity->getHandlerClasses()->willReturn([
'form' => [$operation => $form_class],
]);
}
$this->setUpEntityTypeDefinitions([$entity_type_id => $entity]);
$this->expectException(InvalidPluginDefinitionException::class);
$this->entityTypeManager->getFormObject('test_entity_type', 'edit');
$this->expectExceptionMessage($exception_message);
$this->entityTypeManager->getFormObject($entity_type_id, $operation);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment