How to remove the action of a menu.xml item?
Question
I have a menu.xml like this:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
<add id="Xtento_TrackingImport::menu" action="Xtento_TrackingImport/index/index" title="Some title" module="Xtento_TrackingImport" sortOrder="101" parent="Magento_Sales::sales" resource="Third_Party::menu"/>
</menu>
</config>
I want to remove the 'action' in it. I've try some thing like this in my override menu.xml file :
<update id="Xtento_TrackingImport::menu"/>
And
<update id="Xtento_TrackingImport::menu" action=""/>
And also
<update id="Xtento_TrackingImport::menu" action="#"/>
But none of them work.
Please help, thanks.
Solution
Instead of using update tag in menu.xml, what you can do is create a plugin of menu file in your custom module.
So in your custom module, make following changes.
[Vendor]/[Module]/etc/di.xml
<type name="Magento\Backend\Model\Menu\Config">
<plugin name="custom_override_meu_action" type="[Vendor]\[Module]\Plugin\Config" />
</type>
[Vendor][Module]\Plugin\Config.php
<?php
namespace [Vendor]\[Module]\Plugin;
class Config
{
public function afterGetMenu($subject, $result)
{
$result->get('Xtento_TrackingImport::menu')->setAction(null);
return $result;
}
}
This should work.
OTHER TIPS
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
<update id="Xtento_TrackingImport::menu" action="#"/>
</menu>
</config>
Should work.
But you have to check that your menumenu.xml
code should run after <add id="Xtento_TrackingImport::menu"...
You have to create a new module. this should depend on Xtento_TrackingImport
using <depends><Xtento_TrackingImport/></depends>
and the new module's menu you have to rewrite the update menu code.