Loading core/lib/Drupal/Core/Form/FormBuilder.php +5 −2 Original line number Diff line number Diff line Loading @@ -193,8 +193,11 @@ public function getFormId($form_arg, FormStateInterface &$form_state) { $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 ' . get_class($form_arg) . ' must be an instance of \Drupal\Core\Form\FormInterface.'); } // Add the $form_arg as the callback object and determine the form ID. Loading core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php +16 −3 Original line number Diff line number Diff line Loading @@ -53,12 +53,25 @@ protected function setUp(): void { /** * 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); } Loading Loading @@ -217,7 +230,7 @@ public function testHandleRedirectWithResponse() { 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); } Loading Loading @@ -256,7 +269,7 @@ public function testGetFormWithClassString() { 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 Loading
core/lib/Drupal/Core/Form/FormBuilder.php +5 −2 Original line number Diff line number Diff line Loading @@ -193,8 +193,11 @@ public function getFormId($form_arg, FormStateInterface &$form_state) { $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 ' . get_class($form_arg) . ' must be an instance of \Drupal\Core\Form\FormInterface.'); } // Add the $form_arg as the callback object and determine the form ID. Loading
core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php +16 −3 Original line number Diff line number Diff line Loading @@ -53,12 +53,25 @@ protected function setUp(): void { /** * 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); } Loading Loading @@ -217,7 +230,7 @@ public function testHandleRedirectWithResponse() { 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); } Loading Loading @@ -256,7 +269,7 @@ public function testGetFormWithClassString() { 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