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
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | fix-login-block-constructor-3553925.patch | 1.82 KB | mclewley |
Issue fork email_tfa-3553925
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 #2
avpadernoComment #3
mclewley commentedComment #4
avpadernoWhen new parameters are added, they are added after the last one.
Comment #5
avpadernoFurthermore, now that patches are no longer tested, it is necessary to create a merge request.
Comment #6
mclewley commentedFor 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.
Comment #7
avpadernoIn 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.Comment #10
abdulaziz zaidUpdated the constructor to follow Drupal's backward-compatible deprecation pattern:
-
$form_builder(FormBuilderInterface) is now the 5th parameter, matching the parentUserLoginBlocksignature.- If the old calling convention is used (passing
ConfigFactoryInterfacein position 5), the code detects it viainstanceof, triggers a deprecation notice with@trigger_error(), and resolvesform_builderfrom the container.-
create()method updated to injectform_builderservice.- 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
Comment #12
abdulaziz zaidTested and works as expected. Merging into the dev branch and will be included in the next release (2.0.7).