PHP Fatal error: Type of BpmnIo::$formBuilder must be FormBuilderInterface

Created on 19 June 2025, 4 months ago

Problem/Motivation

When enabling or using the bpmn_io module (version 3.0.0-alpha1) with Drupal 11.2.x and modeler_api (1.0.0-alpha5), a PHP fatal error occurs due to a type mismatch for the $formBuilder property in Drupal\bpmn_io\Plugin\modeler_api_modeler\BpmnIo.

The error is:
Fatal error: Declaration of Drupal\bpmn_io\Plugin\modeler_api_modeler\BpmnIo::enable(): Drupal\modeler_api\Plugin\modeler_api_modeler\ModelerInterface must be compatible with Drupal\modeler_api\Plugin\modeler_api_modeler\ModelerBase::enable(Drupal\modeler_api\Plugin\modeler_api_model_owner\ModelOwnerInterface $owner): Drupal\modeler_api\Plugin\modeler_api_modeler\ModelerInterface in /var/www/html/web/modules/contrib/bpmn_io/src/Plugin/modeler_api_modeler/BpmnIo.php on line 310

The ModelerBase class expects $formBuilder to be an instance of Drupal\Core\Form\FormBuilderInterface, but the BpmnIo class incorrectly type-hints it as Drupal\Core\Form\FormBuilder.

Steps to reproduce

  • Install Drupal 11.2.x.
  • Install modeler_api module (e.g., version 1.0.0-alpha5).
  • Install bpmn_io module (e.g., version 3.0.0-alpha1).

Attempt to enable bpmn_io via Drush or the UI, or navigate to a page that utilizes it.
The fatal error will occur.

Proposed resolution

Update the type hints in web/modules/contrib/bpmn_io/src/Plugin/modeler_api_modeler/BpmnIo.php to use Drupal\Core\Form\FormBuilderInterface:

Change the use statement:

From

use Drupal\Core\Form\FormBuilder;

To

use Drupal\Core\Form\FormBuilderInterface;

Update the property declaration and its PHPDoc:

From

/**
 * The form builder.
 *
 * @var \Drupal\Core\Form\FormBuilder
 */
protected FormBuilder $formBuilder;

To

/**
 * The form builder.
 *
 * @var \Drupal\Core\Form\FormBuilderInterface
 */
protected FormBuilderInterface $formBuilder;

Update the return type of the formBuilder() method and its PHPDoc:

From

/**
 * Get the form builder.
 *
 * @return \Drupal\Core\Form\FormBuilder
 *   The form builder.
 */
protected function formBuilder(): FormBuilder {

To

/**
 * Get the form builder.
 *
 * @return \Drupal\Core\Form\FormBuilderInterface
 *   The form builder.
 */
protected function formBuilder(): FormBuilderInterface {

Applying these changes resolves the fatal error and allows the module to function correctly.

Don't know if you are aware of this issue, if it is just me or if I did anything else wrong. Please let me know and I will be happy to share my patch.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇰🇬Kyrgyzstan dan_metille

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024