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 Thecoachsmb\Mymodule\Plugin;
class RemoveCustomerFeedbackMenu
{
protected $_request;
protected $_authSession;
public function __construct(
\Magento\Framework\App\RequestInterface $request,
\Magento\Backend\Model\Auth\Session $authSession
) {
$this->_request = $request;
$this->_authSession = $authSession;
}
public function afterGetMenu(
\Magento\Backend\Model\Menu\Builder $subject,
\Magento\Backend\Model\Menu $menu
) {
$defaultCountry = $this->_authSession->getUser()->getDefaultCountry();
if ($defaultCountry != 'JP') {
$menu->remove('Thecoachsmb_Mymodule::customerfeedback');
}
return $menu;
}
}
etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Backend\Model\Menu\Builder">
<plugin name="remove_customerfeedback_menu" type="Thecoachsmb\MyModule\Plugin\RemoveCustomerFeedbackMenu" />
</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>