0

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>

2 Answers 2

0

When creating the plugin for a class function, there must be two conditions fulfilled:

  • The class name for which we are creating plugin must be same in the class mentioned in <type name=""> section in di.xml file and in the the plugged-in function in plugin class.
  • The plugged-in function name must exist in the original class.

I checked the \Magento\Backend\Model\Menu\Builder class and could not find getMenu() function in this class.

Please verify that:

  • You are creating plugin for the correct class
  • The function you are trying to create plugin must be present in the original class.
0

After amount of time researching the solution of this. I realized that creating a custom menu was the best solution. Please refer to Menu not showing for custom role in custom module

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.