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

  1. 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.
  2. 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.
  3. Patch it.
  4. Reviews.
  5. RTBC.
  6. 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. :/

CommentFileSizeAuthor
#4 3133102-4.patch1.25 KBdww
#2 3133102-2.patch1.25 KBdww
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dww created an issue. See original summary.

dww’s picture

Issue summary: View changes
Status: Active » Postponed
FileSize
1.25 KB

Don'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

andypost’s picture

RTBC when dependecy in

dww’s picture

FileSize
1.25 KB
dww’s picture

Status: Postponed » Needs review

Yee haw, #2809699: Add configuration options for dynamic block titles landed! This is now up for consideration. Queuing tests.

Kristen Pol’s picture

Status: Needs review » Reviewed & tested by the community

Thanks 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.

[mac:kristen:menu_block8]$ patch -p1 < 3133102-4.patch 
patching file src/Plugin/Block/MenuBlock.php

5) Searching code for setMenuParentFormSelector after patch is applied has no results.

6) Marking RTBC.

  • joelpittet committed e15fff3 on 8.x-1.x authored by dww
    Issue #3133102 by dww, andypost, Kristen Pol: Remove unneeded public...
joelpittet’s picture

Status: Reviewed & tested by the community » Fixed

Surprising 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.