I need help on hiding the Customer Feedback – Article Menu if the default country is not JP.
My code is not working.
Plugin/RemoveCustomerFeedback.php
<?php
namespace ThecoachsmbMymodulePlugin;
class RemoveCustomerFeedbackMenu
{
protected $_request;
protected $_authSession;
public function __construct(
MagentoFrameworkAppRequestInterface $request,
MagentoBackendModelAuthSession $authSession
) {
$this->_request = $request;
$this->_authSession = $authSession;
}
public function afterGetMenu(
MagentoBackendModelMenuBuilder $subject,
MagentoBackendModelMenu $menu
) {
$defaultCountry = $this->_authSession->getUser()->getDefaultCountry();
if ($defaultCountry != 'JP') {
$menu->remove('Thecoachsmb_Mymodule::customerfeedback');
}
return $menu;
}
}
etc/di.xml
<type name="MagentoBackendModelMenuBuilder">
<plugin name="remove_customerfeedback_menu" type="ThecoachsmbMyModulePluginRemoveCustomerFeedbackMenu" />
</type>
“`
etc/menu.xml
<?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="Thecoachsmb_Blog::report_elements"
title="Thecoachsmb Blog"
translate="title"
module="Thecoachsmb_Blog"
sortOrder="15"
parent="Magento_Reports::report"
resource="Magento_Backend::admin"/>
<add id="Thecoachsmb_Mymodule::customerfeedback"
title="Customer Feedback - Article"
translate="title"
module="Thecoachsmb_Mymodule"
sortOrder="20"
parent="Magento_Reports::report"
action="thecoachsmb_mymodule/customerfeedback"
resource="Magento_Backend::admin"/>
</menu>
</config>