If you create a new extension for Magento, chances are that you will need something in the Admin Panel to manage your data. Sometimes, this can be managed from the System > Configuration section, but other times, and new section is needed. In this short post we will give an example of what is needed to create a new menu item in the top navigation in the Admin Panel.
The module that we are working in is the Super_Awesome module. In our local code pool we have a directory structure like:
Super
|_ Awesome
|_etc
| |_ adminhtml.xml
| |_ config.xml
|_Helper
|_ Data.php
If you didn't already know, all of the .xml files in the etc directory get jammed together into one big Config object (notice both files begin with the <config> element), so you can accomplish the same thing in one .xml file or many. The standard is to create many to better separate what is being configured.
adminhtml.xml contents:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<?xmlversion="1.0"?>
<config>
<menu>
<awesometranslate="title"module="awesome">
<title>Awesome</title>
<sort_order>15</sort_order>
<children>
<exampletranslate="title"module="awesome">
<title>Example</title>
<sort_order>1</sort_order>
<action>adminhtml/example/index</action>
</example>
</children>
</awesome>
</menu>
</config>
|
This configuration will create an upper level menu item called "Awesome" and when you hover over it, it will show the child menu item called "Awesome". The <action> tag indicates that if you click on that menu item, it will make a request to the given url. Although the "Example" menu item has an action, if you click on it, it will fail because there is no controller in this example .
config.xml contents:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
<?xmlversion="1.0"?>
<config>
<modules>
<Super_Awesome>
<version>0.1.0</version>
</Super_Awesome>
</modules>
<adminhtml>
<!-- The <layout> updates allow us to define our block layouts in a separate file so are aren't messin' with the Magento layout files. -->
<layout>
<updates>
<awesome>
<file>awesome.xml</file>
</awesome>
</updates>
</layout>
<!-- The <acl> section is for access control. Here we define the pieces where access can be controlled within a role. -->
<acl>
<resources>
<admin>
<children>
<awesome>
<title>Awesome Menu Item</title>
<children>
<exampletranslate="title"module="awesome">
<title>Example Menu Item</title>
</example>
</children>
</awesome>
</children>
</admin>
</resources>
</acl>
</adminhtml>
<global>
<helpers>
<awesome>
<class>Super_Awesome_Helper</class>
</awesome>
</helpers>
</global>
</config>
|
Data.php contents:
1
2
3
4
5
6
|
<?php
classSuper_Awesome_Helper_DataextendsMage_Core_Helper_Abstract
{
}
|
Why an empty class? Well, in some of the xml elements we have defined: translate="title" module="awesome". This tells whatever is reading the config to use the default Helper in the "awesome" module to do its translations of the titles, etc. If you didn't have this, you would see an error like:
Fatal error: Class 'Super_Awesome_Helper_Data' not found in .../magento-1.5.0.1/app/Mage.php on line 523.
That's it! Clear Cache, Logout, Login and your menu item should appear at the top!