Problem/Motivation

As discussed at DrupalCon Atlanta, we want to extend the MenuSource UIPatterns Source plugin so we can decorate it with the rendered content of each menu item (from menu item extras).

This fails with a not found exception, because the method we want to override is private.

Steps to reproduce

Create a new plugin that extends the MenuContent plugin, and attempt to implement getMenuItems().

Whitescreen error.

Proposed resolution

Make MenuSource::getMenuItems a protected method instead of private.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

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

freelock created an issue. See original summary.

freelock’s picture

MR created.

freelock’s picture

Status: Active » Needs review

Updating status.

mortona2k’s picture

Status: Needs review » Reviewed & tested by the community

Fixed the error for me.

just_like_good_vibes’s picture

Hello,
thank you for this issue.
the method you want to expose as protected was not really designed to be opened to subclassas and be treated like an internal API.
why not using directly getPropValue to get the tree of items ?

freelock’s picture

Hi,

Ok, I see that method returns the result of getMenuItems(). We can definitely extend that instead, if that's the only place it gets called.

Cheers,
John

freelock’s picture

Oh sorry, looking again, we're not subclassing that method -- we're just calling it. As a private function we cannot use it -- it needs to be protected so we can call it from our subclass's getPropValue() function.

You can see our usage here: https://git.drupalcode.org/project/megamenu_sdc/-/blame/1.0.x/src/Plugin...

... we could create another copy of this code, but much easier to call existing...

just_like_good_vibes’s picture

Hello. i don’t understand your point ?
you can override getPropValue in your subclass to return what your source is supposed to return, at the same time you can also use getPropValue from the parent class, which is not private.

freelock’s picture

Status: Reviewed & tested by the community » Closed (works as designed)

Hi,

You're right, I get the same thing from the parent getPropValue method.

Cheers,
John

just_like_good_vibes’s picture

you are welcome, we are so happy people enjoy ui patterns 2 :)