0

I am developing a new module which will provide access to a custom grid using left sided admin menu. The problem is that I cannot create a custom element in this admin menu.

The module is located under vendor folder, vendor/test/test-extension, with the following composer.json under module root:

{
  "name": "test/test-extension",
  "description": "test extension magento2",
  "type": "magento2-module",
  "version": "dev-master",
  "autoload": {
    "files": [
      "registration.php"
    ],
    "psr-4": {
      "Test\\TestExtension\\": ""
    }
  }
}

The module is included in autoload_psr4.php, being able to run install schema and getting models.

But, I'm not able to create a custom element in admin menu, simply it doesn't appear.

etc/acl.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
    <acl>
        <resources>
            <resource id="Magento_Backend::admin">
                <resource id="Test_TestExtension::testextension" title="New Extension" sortOrder="52">
                    <resource id="Test_TestExtension::testentity" title="Entity" sortOrder="11"/>
                </resource>
                <resource id="Magento_Backend::stores">
                    <resource id="Magento_Backend::stores_settings">
                        <resource id="Magento_Config::config">
                            <resource id="Test_TestExtension::testextension_config" title="Test Extension"/>
                        </resource>
                    </resource>
                </resource>
            </resource>
        </resources>
    </acl>
</config>

etc/adminhtml/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="Test_TestExtension::testextension" title="Test extension" module="Test_TestExtension" sortOrder="61" resource="Test_TestExtension::testextension"/>
        <add id="Test_TestExtension::testentity" title="Test entity" module="Test_TestExtension" sortOrder="11" action="test_testextension/testentity" resource="Test_TestExtension::testentity" parent="Test_TestExtension::testextension"/>
    </menu>
</config>

Any ideas ?

2 Answers 2

0

Have you set the right to see this new menu ? In the BO : System > Permissions > User Role and modify the Roles Resources for the Administrators ? It could be necessary to set in module.xml a sequence to be sure that your module is after Magento_Backend Module.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Test_TestExtension" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Backend"/>
        </sequence>
    </module>
</config>
7
  • My module.xml looks exactly like that and, unfortunately, my resource does not appear in the user roles either. Commented Jul 23, 2017 at 16:34
  • Are you in developer mode ? If not : bin/magento deploy:mode:set developer Have you launch bin/magento setup:upgrade ? Delete var/di and var/generation ?
    – Marialena
    Commented Jul 23, 2017 at 16:40
  • Yes, I'm in developer mode. I have also performed "setup:upgrade" (where I saw that my module's install schema has been applied) and cache clearing(in magento way "cache:clean" and manually) Commented Jul 23, 2017 at 16:55
  • it's very strange what's happening, because the rest of functionalities are working... for example I can use factory entities from my module Commented Jul 23, 2017 at 16:57
  • Yes, it seems to be a problem in xml files. Have you tried to add only main menu and not sub-menu ? In menu.xml and in acl.xml. And just the menu.xml ? To delete acl.xml.
    – Marialena
    Commented Jul 23, 2017 at 17:21
0

I've made a mistake in registration.php. Wrong version was:

<?php   
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'test_test-extension',
    __DIR__
);

Instead of test_test-extension I've added Test_TestExtension (the module name included in psr4) and it's working fine.

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.