Problem/Motivation
The FormBuilder service is correctly injected into the Block plugin via dependency injection, but it is not used when building the form.
Instead, the plugin currently relies on a static service call:
\Drupal::formBuilder()->getForm(...)
This bypasses the injected service and goes against Drupal best practices, which recommend using dependency injection over static service calls to improve testability and maintainability.
Proposed resolution
Replace the static service call with the injected FormBuilder service.
Specifically, update the code to use:
return $this->formBuilder->getForm($this->searchApiPageBlockForm);
instead of:
return \Drupal::formBuilder()->getForm($this->searchApiPageBlockForm);
This ensures consistent use of dependency injection and aligns the Block plugin with Drupal coding standards and best practices.
Issue fork search_api_page-3568963
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
cicciobat commentedComment #4
anybodyThanks!
Comment #5
karlsheaFixed in #3572395: Code style cleanup, tugboat, gitlab CI & basic Tests