Magento adminhtml.xml files are files that contain information about the menu items in Magento admin area. Magento loads the configuration within these files in the __construct()
method of the Mage_Admin_Model_Config
class.
public function __construct() { parent::__construct(); $this->setCacheId('adminhtml_acl_menu_config'); /* @var $adminhtmlConfig Varien_Simplexml_Config */ $adminhtmlConfig = Mage::app()->loadCache($this->getCacheId()); if ($adminhtmlConfig) { $this->_adminhtmlConfig = new Varien_Simplexml_Config($adminhtmlConfig); } else { $adminhtmlConfig = new Varien_Simplexml_Config; $adminhtmlConfig->loadString('<?xml version="1.0"?><config></config>'); Mage::getConfig()->loadModulesConfiguration('adminhtml.xml', $adminhtmlConfig); $this->_adminhtmlConfig = $adminhtmlConfig; /** * @deprecated after 1.4.0.0-alpha2 * support backwards compatibility with config.xml */ $aclConfig = Mage::getConfig()->getNode('adminhtml/acl'); if ($aclConfig) { $adminhtmlConfig->getNode()->extendChild($aclConfig, true); } $menuConfig = Mage::getConfig()->getNode('adminhtml/menu'); if ($menuConfig) { $adminhtmlConfig->getNode()->extendChild($menuConfig, true); } if (Mage::app()->useCache('config')) { Mage::app()->saveCache($adminhtmlConfig->getXmlString(), $this->getCacheId(), array(Mage_Core_Model_Config::CACHE_TAG)); } } }
The key line is where loadModulesConfiguration()
is called.
Mage::getConfig()->loadModulesConfiguration('adminhtml.xml', $adminhtmlConfig);
The loadModulesConfiguration()
method is also used to load Magento’s config.xml
and system.xml
files.
<config> <menu> <dashboard translate="title" module="adminhtml"> <title>Dashboard</title> <sort_order>10</sort_order> <action>adminhtml/dashboard</action> </dashboard> <system translate="title" module="adminhtml"> <title>System</title> <sort_order>90</sort_order> <!-- action>adminhtml/system</action --> .... </system> .... </menu> </config>
So we can see that the menu is wrapped within a pair of menu
tabs. Let’s take a look at the nodes used.
title
– the title of the menu item that will appear on the frontend of the admin area.sort_order
– the order of which the menu items appear in the admin.action
– the URL that the menu item should follow.The menu items may have children menu items as well. Some of the configuration from the adminhtml.xml
file of the Mage_Adminhtml
module can be seen below.
<config> <menu> <dashboard translate="title" module="adminhtml"> <title>Dashboard</title> <sort_order>10</sort_order> <action>adminhtml/dashboard</action> </dashboard> <system translate="title" module="adminhtml"> <title>System</title> <sort_order>90</sort_order> <!-- action>adminhtml/system</action --> <children> <myaccount translate="title"> <title>My Account</title> <action>adminhtml/system_account</action> <sort_order>10</sort_order> </myaccount> .... </children> </system> .... </menu> </config>
The children nodes contain the same nodes as the parent menu items.
The adminhtml.xml
files also contain ACL information, but we will cover this is another article.
To learn more about how Magento loads its system.xml
files, view this post.
Note: This article is based on Magento Community/Open Source version 1.9.