Creating an MCV/MVVM landing page for Magento 2’s frontend cart application is relatively simple. You create a
routes.xml file so your module can “claim” a frontname, then then create a controller class that’s named correctly to catch a particular URL pattern. This is even easier with pestle, my PHP CLI module framework and Magento code generation tool.
$ pestle.phar generate_route Pulsestorm_HelloGenerate frontend pulsestorm_hellogenerate
Admin landing pages, however, are a bit trickier. That’s because, in addition to a standard
routes.xml and controller file, you also need to contend with
- Every Admin URL needs a nonce/key to prevent XSS attacks, which means adding a formal “Admin Menu Item” to the system
- Every formal “Admin Menu Item” needs to be associated with a User Role/Access Control Rule
- Every Admin controller needs to be associated with a User Role/Access Control Rule (often the same as the menu)
The Formal Menu Item means a link that shows up in a left side navigation sub-menu.
Today I’ve pushed some changes to pestle that ensure you can use it to create an admin route. The following commands will create a module named
Pulsestorm_HelloAdmin, and add an ACL protected link under the
System -> Other Settings menu
$ pestle.phar generate_module Pulsestorm HelloAdmin2 0.0.1 $ pestle.phar generate_acl Pulsestorm_HelloAdmin2 Pulsestorm_HelloAdmin2::top,Pulsestorm_HelloAdmin2::config $ pestle.phar generate_route Pulsestorm_HelloAdmin2 adminhtml pulsestorm_helloadmin2 $ pestle.phar generate_menu Pulsestorm_HelloAdmin2 Magento_Backend::system_other_settings Pulsestorm_HelloAdmin2::pulsestorm_helloadmin2_index_index Pulsestorm_HelloAdmin2::pulsestorm_helloadmin2_index_index "Link to Hello Admin Landing Page" "pulsestorm_helloadmin2/index/index" 10
I’m working on a tenth article for my Magento 2 for PHP Developers series that will cover what these commands do, and what Magento uses each created file is for. However, until that’s written, the above should be enough to get you going on your admin modules, and don’t forget that all arguments to a pestle command are interactive – running
pestle.phar generate_menu without arguments should help you understand what each entered value is for.
Finally – there’s two things you’ll still need to do manually
- Enter titles for your new ACL rules in the generated
- Enter the ACL rule ID in the generated
As always, if you run into any trouble or see room for improvement, GitHub issues are welcomed.