Issue #2965929 by jhedstrom, dimitriskr, kkalashnikov, sun, Lendude, DanielVeza: DX: Insufficient error message "The form argument is not a valid form."
parent
43a384bae1
commit
12e26bd476
|
@ -193,8 +193,11 @@ class FormBuilder implements FormBuilderInterface, FormValidatorInterface, FormS
|
|||
$form_arg = $this->classResolver->getInstanceFromDefinition($form_arg);
|
||||
}
|
||||
|
||||
if (!is_object($form_arg) || !($form_arg instanceof FormInterface)) {
|
||||
throw new \InvalidArgumentException("The form argument $form_arg is not a valid form.");
|
||||
if (!is_object($form_arg)) {
|
||||
throw new \InvalidArgumentException(("The form class $form_arg could not be found or loaded."));
|
||||
}
|
||||
elseif (!($form_arg instanceof FormInterface)) {
|
||||
throw new \InvalidArgumentException('The form argument ' . $form_arg::class . ' must be an instance of \Drupal\Core\Form\FormInterface.');
|
||||
}
|
||||
|
||||
// Add the $form_arg as the callback object and determine the form ID.
|
||||
|
|
|
@ -53,12 +53,25 @@ class FormBuilderTest extends FormTestBase {
|
|||
|
||||
/**
|
||||
* Tests the getFormId() method with a string based form ID.
|
||||
*
|
||||
* @covers ::getFormId
|
||||
*/
|
||||
public function testGetFormIdWithString() {
|
||||
$form_arg = 'foo';
|
||||
$form_state = new FormState();
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('The form argument foo is not a valid form.');
|
||||
$this->expectExceptionMessage('The form class foo could not be found or loaded.');
|
||||
$this->formBuilder->getFormId($form_arg, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getFormId
|
||||
*/
|
||||
public function testGetFormIdWithNonFormClass() {
|
||||
$form_arg = __CLASS__;
|
||||
$form_state = new FormState();
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage("The form argument $form_arg must be an instance of \Drupal\Core\Form\FormInterface.");
|
||||
$this->formBuilder->getFormId($form_arg, $form_state);
|
||||
}
|
||||
|
||||
|
@ -217,7 +230,7 @@ class FormBuilderTest extends FormTestBase {
|
|||
public function testGetFormWithString() {
|
||||
$form_id = 'test_form_id';
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('The form argument test_form_id is not a valid form.');
|
||||
$this->expectExceptionMessage('The form class test_form_id could not be found or loaded.');
|
||||
$this->formBuilder->getForm($form_id);
|
||||
}
|
||||
|
||||
|
@ -256,7 +269,7 @@ class FormBuilderTest extends FormTestBase {
|
|||
public function testBuildFormWithString() {
|
||||
$form_id = 'test_form_id';
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('The form argument test_form_id is not a valid form.');
|
||||
$this->expectExceptionMessage('The form class test_form_id could not be found or loaded.');
|
||||
$this->formBuilder->getForm($form_id);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue