Problem/Motivation

As of Drupal 11 the UserLoginBlock constructor requires the $formBuilder argument, see https://www.drupal.org/node/3159776 . Previously the parent class constructor allowed a nullable $formBuilder argument. This was however deprecated in drupal 10.3.0 and now required in drupal 11. The following error will be thrown during updatedb process when upgrading to any version of drupal 11.

[error] ArgumentCountError: Too few arguments to function Drupal\user\Plugin\Block\UserLoginBlock::__construct(), 4 passed in /app/web/modules/contrib/email_tfa/src/Plugin/Block/EmailTfaUserLoginBlock.php on line 52 and exactly 5 expected in Drupal\user\Plugin\Block\UserLoginBlock->__construct() (line 57 of /app/web/core/modules/user/src/Plugin/Block/UserLoginBlock.php)

Steps to reproduce

1. Be on module version ^2.0.
2. Upgrade site to Drupal 11
3. Run drush updatedb -> this will trigger the error.

Proposed resolution

Created a patch file and attached. Seems to resolve the issue and allow for drush updatedb to complete.

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork email_tfa-3553925

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

mclewley created an issue. See original summary.

avpaderno’s picture

Version: 2.0.5 » 2.0.x-dev
Status: Patch (to be ported) » Needs review
mclewley’s picture

StatusFileSize
new1.82 KB
avpaderno’s picture

Status: Needs review » Needs work
+   * @param \Drupal\Core\Form\FormBuilderInterface $formBuilder
+   *   The form builder.
    * @param ConfigFactoryInterface $config_factory
    *   The configuration factory.
    */
-  public function __construct(array $configuration, string $plugin_id, $plugin_definition, RouteMatchInterface $route_match, ConfigFactoryInterface $config_factory) {
-    parent::__construct($configuration, $plugin_id, $plugin_definition, $route_match);
+  public function __construct(array $configuration, string $plugin_id, $plugin_definition, RouteMatchInterface $route_match, FormBuilderInterface $formbuilder, ConfigFactoryInterface $config_factory) {
+    parent::__construct($configuration, $plugin_id, $plugin_definition, $route_match, $formbuilder);
     $this->configFactory = $config_factory;

When new parameters are added, they are added after the last one.

avpaderno’s picture

Issue tags: +Needs merge request

Furthermore, now that patches are no longer tested, it is necessary to create a merge request.

mclewley’s picture

For this case we don't want to add the $formBuilder parameter after the $config_factory. Since we are extending a class, we should match the signature of the parent class. I will create a merge request for this, thank you for that info.

avpaderno’s picture

Since we are extending a class, we should match the signature of the parent class.

In that case, the change cannot be as simple as adding a new parameter for the constructor, especially for a module that declares itself compatible with Drupal 9, Drupal 10, and Drupal 11. At least, the code should call trigger_error(), when the parameters are not in the expected order.

abdulaziz zaid made their first commit to this issue’s fork.

abdulaziz zaid’s picture

Status: Needs work » Needs review

Updated the constructor to follow Drupal's backward-compatible deprecation pattern:

- $form_builder (FormBuilderInterface) is now the 5th parameter, matching the parent UserLoginBlock signature.
- If the old calling convention is used (passing ConfigFactoryInterface in position 5), the code detects it via instanceof, triggers a deprecation notice with @trigger_error(), and resolves form_builder from the container.
- create() method updated to inject form_builder service.
- This maintains full backward compatibility across Drupal 9, 10, and 11.

The deprecation can be removed cleanly in email_tfa:3.0.0.

MR: !31

  • abdulaziz zaid committed 2b417e08 on 2.0.x
    feat: #3553925 Fix EmailTfaUserLoginBlock constructor for Drupal 11...
    
abdulaziz zaid’s picture

Status: Needs review » Fixed

Tested and works as expected. Merging into the dev branch and will be included in the next release (2.0.7).

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.