I need to add some elements in the admin menu based on some conditions (custom logic) so I cannot use adminhtml/menu.xml
for that. (or can I?)
For example, I need to add inside the products main menu the next structure
- Accessories
- Accessories type 1
- Accessories type 2.
- …
- Accessories type N.
Numbers 1 to N are dynamic and may come from different extensions that link to the same class.
Is there an event I can hook on? Or some class I can pluginize?
Best Answer
The solution for Magento 1 mentioned by @avesh in the comments above also applies to Magento 2. You can still listen to event
adminhtml_block_html_before
. The sample code below adds a "Test Menu" under "Catalog".app/code/Vendor/Module/etc/adminhtml/events.xml:
app/code/Vendor/Module/Observer/AdminhtmlBlockHtmlBefore.php: