Commit 751983cb authored by catch's avatar catch
Browse files

Revert "Issue #2965929 by jhedstrom, dimitriskr, kkalashnikov, sun, Lendude,...

Revert "Issue #2965929 by jhedstrom, dimitriskr, kkalashnikov, sun, Lendude, DanielVeza: DX: Insufficient error message "The form argument is not a valid form.""

This reverts commit a12680a1.
parent 75f9f83f
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -193,11 +193,8 @@ public function getFormId($form_arg, FormStateInterface &$form_state) {
      $form_arg = $this->classResolver->getInstanceFromDefinition($form_arg);
    }

    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.');
    if (!is_object($form_arg) || !($form_arg instanceof FormInterface)) {
      throw new \InvalidArgumentException("The form argument $form_arg is not a valid form.");
    }

    // Add the $form_arg as the callback object and determine the form ID.
+3 −16
Original line number Diff line number Diff line
@@ -53,25 +53,12 @@ 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 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->expectExceptionMessage('The form argument foo is not a valid form.');
    $this->formBuilder->getFormId($form_arg, $form_state);
  }

@@ -230,7 +217,7 @@ public function testHandleRedirectWithResponse() {
  public function testGetFormWithString() {
    $form_id = 'test_form_id';
    $this->expectException(\InvalidArgumentException::class);
    $this->expectExceptionMessage('The form class test_form_id could not be found or loaded.');
    $this->expectExceptionMessage('The form argument test_form_id is not a valid form.');
    $this->formBuilder->getForm($form_id);
  }

@@ -269,7 +256,7 @@ public function testGetFormWithClassString() {
  public function testBuildFormWithString() {
    $form_id = 'test_form_id';
    $this->expectException(\InvalidArgumentException::class);
    $this->expectExceptionMessage('The form class test_form_id could not be found or loaded.');
    $this->expectExceptionMessage('The form argument test_form_id is not a valid form.');
    $this->formBuilder->getForm($form_id);
  }