Document registering a custom Menu in Config/services.php (Mautic 8) - #627
Document registering a custom Menu in Config/services.php (Mautic 8)#627promptless-for-oss wants to merge 1 commit into
Conversation
Mautic 8 (mautic/mautic PR #17116) removed the ServicePass compiler pass and the 'services > menus' array in bundle Config/config.php. Add a 'Registering a custom Menu' section to plugins/config.rst documenting the knp_menu.menu MenuItem and knp_menu.renderer MenuRenderer services a Plugin now declares in Config/services.php, with a before/after migration example and a forward cross-reference from 'Available menus'.
|
|
||
| The :ref:`plugins/config:Menu config items` section adds items to Mautic's four built-in menus through the ``menu`` config array. This section covers the opposite direction: registering a Plugin's own top-level Menu, with its own template and renderer. | ||
|
|
||
| .. note:: |
There was a problem hiding this comment.
Confirms Mautic 8 (mautic/mautic PR #17116, merged into 8.x at commit 8da44fa2) deleted the ServicePass compiler pass and removed its registration from MauticCoreBundle::build(); the services > menus array in Config/config.php is no longer processed.
|
|
||
| Mautic 8 removed the ``ServicePass`` compiler pass and the ``services > menus`` array in ``Config/config.php``. A Plugin now declares its Menu item and renderer explicitly in ``Config/services.php``. | ||
|
|
||
| Registering a custom Menu takes two services in your Plugin's ``Config/services.php``: |
There was a problem hiding this comment.
CoreBundle's own Config/services.php registers each menu as a Knp\Menu\MenuItem tagged knp_menu.menu and a Mautic\CoreBundle\Menu\MenuRenderer tagged knp_menu.renderer, each with ['alias' => ] — the pattern documented for plugin bundles.
| use Mautic\CoreBundle\Menu\MenuBuilder; | ||
| use Mautic\CoreBundle\Menu\MenuRenderer; | ||
|
|
||
| use function Symfony\Component\DependencyInjection\Loader\Configurator\service; |
There was a problem hiding this comment.
MenuBuilder::__call() strips the trailing "Menu" from the invoked method name and builds the menu by that alias, confirming the documented 'Menu' factory-method pattern (e.g. mybundleMenu) works for any custom alias, not just CoreBundle's built-in menus.
|
|
||
| // ... inside the configurator closure, using the same $services | ||
|
|
||
| $services->set('mautic.menu.mybundle', MenuItem::class) |
There was a problem hiding this comment.
MenuRenderer::__construct(MatcherInterface $matcher, Environment $twig, array $defaultOptions = []) matches the documented ->args([service('knp_menu.matcher'), service('twig'), $options]) pattern.
| $services->set('mautic.menu.mybundle', MenuItem::class) | ||
| ->factory([service(MenuBuilder::class), 'mybundleMenu']) | ||
| ->tag('knp_menu.menu', ['alias' => 'mybundle']); | ||
|
|
There was a problem hiding this comment.
Merge commit for mautic/mautic PR #17116 (merged into 8.x) removes the line $services->alias('mautic.menu.builder', Mautic\CoreBundle\Menu\MenuBuilder::class); from CoreBundle/Config/services.php; the alias is absent from the merged 8.x file, confirming service(MenuBuilder::class) must be referenced by class.
Source: mautic/mautic@8da44fa
|
I noticed that some CI checks failed for this PR. I'm investigating whether the failures are caused by this suggestion. If they're unrelated or pre-existing, I'll leave this suggestion unchanged and create a separate suggestion if a standalone docs fix is needed. |
Open in Promptless
Mautic 8 (mautic/mautic PR #17116) removed the
ServicePasscompiler pass and theservices > menusarray in a bundle'sConfig/config.php. A Plugin that registered its own top-level Menu must now declare two services explicitly inConfig/services.php: aKnp\Menu\MenuItemtaggedknp_menu.menu, and aMautic\CoreBundle\Menu\MenuRenderertaggedknp_menu.renderer, paired by a matchingaliastag argument.This adds a "Registering a custom Menu" section to
docs/plugins/config.rstdocumenting this previously-undocumented extension point and its migration path — a before (config.php) / after (services.php) example, the multi-menu loop form, and a note that the menu builder must be referenced by class (Mautic\CoreBundle\Menu\MenuBuilder::class) because themautic.menu.builderstring alias was removed. A forward cross-reference from the "Available menus" list points readers to the new section.Trigger Events