KnpMenu icon indicating copy to clipboard operation
KnpMenu copied to clipboard

Overriding Matcher::isAncestor method

Open BoShurik opened this issue 5 months ago • 3 comments

Hello.

I have a simple menu which contains top level links (e.g. Home, Orders, News etc). Concrete news are not included, as I don't render them and there are many of them.

Before 3.8.0 I extend \Knp\Menu\Matcher\Matcher and override isAncestor method so it can detect child pages by request uri and mark parent items as ancestors.

Now Matcher is final and I can't do that. I tried to decorate Matcher but it uses recursive calls so it's impossible to achieve what I want.

Is it possible to revert this change? Or there is another way to achieve this? (except copy pasting Matcher)

BoShurik avatar Jul 10 '25 14:07 BoShurik

The class was made final exactly to avoid the burden of supporting extensions. It's anyway a small class, and so I don't see big problems in copying/pasting it to your custom implementation.

garak avatar Jul 10 '25 14:07 garak

My approach there would be to actually configure the News page as being matched as active for any concrete news (as those are not rendered anyway). But it is true that I don't make any difference between a current item and an ancestor item with children not rendered in my menu styles.

stof avatar Jul 10 '25 15:07 stof

@stof Nice, I'll try that

BoShurik avatar Jul 10 '25 15:07 BoShurik