After updating drupal/facets from 3.0.3 to 3.0.4, phpstan reports the following error in our custom Facets widget:
Method Drupal\facets\Widget\WidgetPluginBase::__construct() invoked
with 3 parameters, 4 required.
It looks like a new required argument was added to the WidgetPluginBase constructor.
Since this was introduced in a patch release (3.0.3 -> 3.0.4), it creates a backwards compatibility break for existing custom or contributed widgets extending WidgetPluginBase.
A BC/deprecation layer should have been provided when changing the constructor arguments, as described in Drupal's deprecation guidelines. See https://www.drupal.org/about/core/policies/core-change-policies/how-to-d...
A similar issue was already reported for the Select2 module:
https://www.drupal.org/project/select2/issues/3618004
Steps to reproduce
- Have a custom widget extending WidgetPluginBase using the constructor from Facets 3.0.3.
- Update Facets to 3.0.4.
- Run PHPStan.
Proposed resolution
Keep backwards compatibility with the previous constructor and introduce the new argument using a BC/deprecation layer.
Issue fork facets-3618467
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:
- facets-3618467
changes, plain diff MR !401
- 3618467-facets
compare
Comments
Comment #2
ioana apetri commentedComment #4
ioana apetri commentedComment #5
joelpittetRe targetting to the dev release because that is where the fix will be applied.
Comment #7
joelpittetThanks @ioana for the issue and MR. I am taking in a bit of a different direction and I want to explain myself a bit.
The constructor changes all came from #3589162: Support special hierarchy processors as exposed filters in
3.0.4and unintentionally introduced a BC break. MR !401 uses the right deprecation pattern for a minor release, but adding new deprecations in a patch release would create another semver problem.For
3.0.7I’ve therefore reverted the affected constructor changes inWidgetPluginBaseandLinksWidgetback to their3.0.3versions. Those two need to move together becauseLinksWidgetrelies on the service injected by its parent.I also checked contrib usage and confirmed these are the classes causing the live
ArgumentCountErrorfailures, including the Select2 report.The dependency injection work is still worth keeping. MR !401 looks like the right basis to reintroduce it properly in 3.1.x, where we can add the necessary deprecation layer.
I hope this sits well with you? I feel this is the only issue I want to address before the next patch release that should get things back to a stable footing. If you're ok with this direction, I will get this in and a release out ASAP. Want to run the changes by you first though.
Comment #8
joelpittetI am going to merge that and we can revisit the deprecation for a minor in a separate issue. This helps unblock (in my mind) a patch release for D10
Thanks again @ioana for getting this off the ground!