Following our introduction to custom Magento reports, we now present a tutorial on adminhtml.xml reports - the latest in our tips to help you learn a little bit of Magento custom development.
adminhtml.xml files are only for Magento versions 1.4 and higher, with Magento versions prior to 1.4 storing all of the adminhtml.xml info in the config.xml file. For newer versions of Magento, use of the adminhtml.xml is optional but it is still preferred for code clarity.
The adminhtml.xml contains nodes for defining the access control lists (ACL) as well as declaring menu items so that an admin is able to access the extension controller(s).
Magento Custom Development - adminhtml.xml
Menu
The menu node declares how the Reports will be accessed by the Magento Admin and which controller should be triggered when the menu item is selected. Because there are multiple cost reports, it was decided to add a new menu called “Cost Analysis” instead of integrating the cost reports into the “Sales” and “Product” report areas.
<menu>
<report>
<children>
<costanalysis translate="title" module="costreport">
<title>Cost Analysis</title>
<sort_order>30</sort_order>
<depends>
<module>Eyemagine_CostReport</module>
</depends>
<children>
<sales translate="title" module="costreport">
<title>Sales Summary</title>
<action>adminhtml/report_cost_sales/summary</action>
<sort_order>10</sort_order>
</sales>
<product translate="title" module="costreport">
<title>Products</title>
<action>adminhtml/report_cost_product/cost</action>
<sort_order>20</sort_order>
</product>
</children>
</costanalysis>
</children>
</report>
</menu>
One of the most important areas defined above is the action. If written incorrectly, your extension controller will not be found, or it might load a completely different controller if the path name you defined was not unique.
It might appear that the controller belongs to the “Mage_Adminhtml” extension. This is one of the areas that goes against typical Magento class name identifiers, and does not mean that the controller has to live directly inside the Adminhtml extension (after all that would break MVC and the extendability of Magento).
Instead, because of the extension config.xml router declaration that “Eyemagine_CostReport_Adminhtml” should be called before “Mage_Adminhtml”, our extension controller will be called before Magento looks in the “Mage_Adminhtml” extension. For that reason, we can imagine that that “adminhtml” is replaced with Eyemagine_CostReport_Adminhtml in the first section of the action.
The second section defines the admin controller path starting after the controllers “Adminhtml” directory. Because we are not replacing the functionality of an existing Magento controller, we need to make sure that our class path is unique (otherwise we could unexpectedly break Magento functionality).
The final section is optional and defines the action name that will be called within the controller. If left blank, the “index” action will be called.
To locate our controller in the file system, it would be under the following path:
app > code > local > Eyemagine > CostReport > controllers > Adminhtml > Report > Cost > ProductController.php
And the name of the class would be:
Eyemagine_CostReport_Adminhtml_Report_Cost_ProductController
ACL
ACL or “Access Control Lists” enables permission based access to the report. By providing a separate ACL for this report, it will allow the Magento administrators to decide which of the staff is able to access each report.
While the Cost report may not contain sensitive info, administrators might want to prevent warehouse or shipping staff from accessing all sales related content, but still allow them to have access to the other “product” related reports.
<acl>
<resources>
<admin>
<children>
<report>
<children>
<costanalysis translate="title" module="costreport">
<title>Cost Analysis Reports</title>
<sort_order>40</sort_order>
<children>
<sales translate="title" module="costreport">
<title>Sales Summary</title>
<sort_order>10</sort_order>
</sales>
<product translate="title" module="costreport">
<title>Products</title>
<sort_order>20</sort_order>
</product>
</children>
</costanalysis>
</children>
</report>
</children>
</admin>
</resources>
</acl>
The ACL uses the same node name as the menu item declared in the first adminhtml section. There might be multiple reports added with the CostReport extension and the ACL should reflect each unique report.
If you have any further questions about this tutorial or about how to develop Magento adminhtml.xml reports, contact one of our Magento experts today. We're standing by to help.