Make MultistepController easy overrided

Created on 22 January 2025, 3 months ago

Problem/Motivation

The MultistepController is difficult to extend because everything is built within the rebuildForm method. If you only need to modify the buttons, you must implement hook_simple_multistep_controller_alter, which involves overriding both the class and the entire rebuildForm method.

For example, if you want to add one more button—such as a “Draft” button—you must override the entire method just to include this new button. This approach can be problematic for maintenance, since future versions of the module might significantly change the rebuildForm method, forcing you to update your custom code to remain compatible.

Of course, there are other ways to achieve similar results. However, following the module’s recommended approach to extend MultistepController via hook_simple_multistep_controller_alter, the class could ideally be structured to break down features into smaller, more manageable pieces.

Steps to reproduce

Proposed resolution

We could separate the method in functions, like:

public function rebuildForm(array &$form): void {
    $this->addStepIndicator($form);
    $this->addButtons($form);
    $this->addFormText($form);
    $this->processSteps($form);
  }

Then, if I want to modify the the buttons I just have to override the addButtons method.

Remaining tasks

  • Write unit tests
  • Discuss with the mainterns the approach suggested
Feature request
Status

Active

Version

2.0

Component

Code

Created by

🇧🇷Brazil joaopauloc.dev

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024