Problem/Motivation
At #3115436: Use proper dependency injection and protect menu_block from changes to the SystemMenuBlock constructor we added a public setMenuParentFormSelector() method to the MenuBlock plugin.
https://www.previousnext.com.au/blog/safely-extending-drupal-8-plugin-cl... for background.
However, we don't actually need that. ;) As @alexpott pointed out with the snippet at https://3v4l.org/KSYat -- static factory methods can access protected members on their newly created instances, without needing public methods.
See patch and interdiff at #2809699-159: Add configuration options for dynamic block titles for a working example of a similar dependency injection on this plugin where we don't need to introduce a new public setter.
Proposed resolution
Remove MenuBlock::setMenuParentFormSelector()
and set $instance->menuParentFormSelector
directly in MenuBlock::create()
.
Remaining tasks
- Wait for #2809699: Add configuration options for dynamic block titles to land, since any patch here will conflict with that, and I don't want to further delay that issue.
- Decide the BC implications of this change. :/ Sadly, we didn't realize this at #3115436 and already shipped 8.x-1.6 with the public setter. So in theory, someone could be using that already. But I say screw 'em. No one has any business mucking with this stuff. It was a freshly added piece of the public API, it's only been out for a week or so. But maybe we should do the whole deprecation hoop jumping and only remove this in a forthcoming 2.x branch.
Patch it.- Reviews.
- RTBC.
- Commit.
User interface changes
None.
API changes
Removing a piece of public API on the MenuBlock plugin that shouldn't have been added in the first place.
Data model changes
None.
Release notes snippet
TBD. Depends on what we decide above about BC stuff. :/
Comment | File | Size | Author |
---|---|---|---|
#4 | 3133102-4.patch | 1.25 KB | dww |
|
Comments
Comment #2
dwwDon't queue this for the testbot yet, since I rolled it on top of #2809699-159: Add configuration options for dynamic block titles, but here's a simple patch to implement this (assuming we don't do the whole deprecation song/dance). Once #2809699 lands, this should test cleanly and show we don't need the public setter.
Enjoy,
-Derek
Comment #3
andypostRTBC when dependecy in
Comment #4
dwwRe-roll for #2809699-161: Add configuration options for dynamic block titles.
Comment #5
dwwYee haw, #2809699: Add configuration options for dynamic block titles landed! This is now up for consideration. Queuing tests.
Comment #6
Kristen PolThanks for the update.
1) @andypost already said in #3 it should be RTBCed once the dependency landed which has.
2) Last patch was just a reroll.
3) Tests have passed.
4) Patch applies cleanly.
5) Searching code for
setMenuParentFormSelector
after patch is applied has no results.6) Marking RTBC.
Comment #8
joelpittetSurprising PHPStorm doesn't complain anymore with this approach in either way... anyways less public API:) Thanks for the patch @dww. Committed and pushed to the dev branch.