Skip to content

Method Drupal\Core\Form\FormBuilderInterface::getForm() invoked with 2 parameters, 1 required. #892

@tlo450

Description

@tlo450

Bug report

In my project (currently on Drupal 10.5.1), I'm adding an extra parameter in getForm() like this:

$this->formBuilder->getForm(AccountLoginForm::class, ['param_here' => 'value_here']);

Then in AccountLoginForm.php, I have this:

buildForm(array $form, FormStateInterface $form_state, ?array $options = NULL)

I would then use $options['param_here'] in my form. Which all works perfectly... however I'm getting this phpstan error when running a scan:

Method Drupal\Core\Form\FormBuilderInterface::getForm() invoked with 2 parameters, 1 required.

What doesn't make sense to me though...is that I see Drupal core (10.5.x.) doing this as well. For example, in SystemController.php which is calling this form.

I'm doing the same thing here... so I guess I'm a little confused as to why I'm seeing this error?

The one thing I thought of though...is that Drupal core is using level 1 in their phpstan file (whereas I'm using level 2 in my project). I don't know if that should really matter though?

I do see in the 10.x documentation that getForm() should only have 1 parameter (11.x does show the 2nd parameter) however...then why is core (10.5.x) using that 2nd parameter? I'm following what core is doing, so I'm a little surprised that I'm running into this problem. Is this an actual bug then?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions