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.

Command icon 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

cicciobat created an issue. See original summary.

cicciobat’s picture

Issue summary: View changes
anybody’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

karlshea’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.