adminhtml.xml in details

adminhtml.xml in details

At the beginning there was config.xml. It contain module configuration information for all “areas”, like frontend, adminhtml, global etc. Since magento does consist of a lot of modules resulting configuration object has rather big size. To reduce its size and speed up frontend developers decide to separate admin information from config.xml. adminhtml.xml was presented in magento 1.4. It contain nodes for access control lists ( ACL ) and admin menu items. Use of adminhtml.xml is optional. You could store acl / menu info in config.xml

adminhtml.xml nodes

1. Admin menu items

<menu>
	 <cms translate="title" module="cms">
		<title>CMS</title>
		<sort_order>70</sort_order>
		<children>
			<page translate="title" module="cms">
				<title>Pages</title>
				<action>adminhtml/cms_page</action>
				<sort_order>0</sort_order>
			</page>
			<block translate="title" module="cms">
				<title>Static Blocks</title>
				<action>adminhtml/cms_block</action>
				<sort_order>10</sort_order>
			</block>
		</children>
	 </cms>
</menu>

<title/> – item text
<action/> – item route ( URL )
<sort_order/> – item position in admin menu
<children/> – item children ( submenu )

2. Access control lists

<acl>
	<resources>
		<admin>
			<children>
				<cms translate="title" module="cms">
					<title>CMS</title>
					<sort_order>70</sort_order>
					<children>
						<block translate="title">
							<title>Static Blocks</title>
							<sort_order>10</sort_order>
						</block>
					</children>
				</cms>
			</children>
		</admin>
	</resources>
</acl>

As you can see it use same hierarchical pattern as menu node.

What about other adminhtml nodes?

adminhtml.xml loaded in app/code/core/Mage/Admin/Model/Config.php

Mage::getConfig()->loadModulesConfiguration('adminhtml.xml', $adminhtmlConfig);

But it use only acl and menu nodes.

/**
 * @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);
}

Not sure why but other nodes still kept in config.xml. So if your module use events, you want to add translate file or declare layout update for admin – you need to use config.xml

Summary

Use adminhtml.xml to store module ACL and menu nodes. It makes your main config file more readable. You can still use config.xml for that purpose, but it might be removed in future releases. So keep in mind that adminhtml node in config.xml could be just for backwards compatibility.

Leave a Reply

Your email address will not be published. Required fields are marked *