Adding sections to the admin area is in some ways very different to Magento 1. In this tutorial I’m not going to cover admin grids, instead I’m going to focus on creating a grid-less admin page and adding to the configuration.
The Magento 2 configuration is now found in Stores > Settings > Configuration, however a familiar file is needed to add to this:
In the example below I have created a new tab called “Magento Fox” with a section called “Settings” underneath. There is then a option group called “Settings” with a single Yes/No field called “Show Something?”.
There are obviously tonnes more options you can choose from here - my suggestion is to look at the core modules system.xml to find the code you need for each field type. The options are basically the same as Magento 1 system.xml.
Step 2 - Create Magefox/Example/etc/config.xml
Config.xml is back, except this time is for setting default configuration values only. At least it’s a lot more readable this time round!
Creating an actual page in the admin requires a bit more work because (like the frontend) we have to create a controller using the admin route object and we have to build blocks to make the content. Grids & forms aside, this is how you do it:
Now you have to decide how you want people to be able to access your page by creating a conveniently named “menu.xml” file within etc/adminhtml.
In the example above I have added a new section to the “Stores” tab which is referenced in the first <add> node where it says parent=”Magento_Backend::stores”. Underneath this I have then added a link to my new page which will be located at magefox/foxypage, and I’ve also linked to our new configuration page we created above.
Step 3 - Create Magefox/Example/etc/acl.xml
We need to ensure that our admin page can be restricted to certain users only. This can be done by making it available to the ACL object.
We create our admin controller action in pretty much the same way as the frontend action, an execute method renders the page. An additional method here will also check that the user has the sufficient priveledges that we assigned above using ACL.