Site icon Nabtron

How to add new custom menu type in Joomla! 1.5 tutorial

Joomla! provides four menu types by default

However if some one wants to add new menu type to the predefined menu types in joomla backend, this tutorial guides them through it easily.  It involves only three steps and is tested on Joomla! 1.5

In this tutorial we will add new menu type to our joomla mod_mainmenu and name it test_type. To add custom menu type to Joomla! 1.5 mod_mainmenu, please follow these steps (make sure to backup the mod_mainmenu folder out side joomla directory – donot save the copy in the same modules folder – before attempting to follow the tutorial to save you from any trouble in future):

1. Add custom new menu type to Joomla administration module manager:

In first step we will define a new custom menu type to be listed and shown in the Joomla! administration backend module manager with the list of other four already existing joomla menu types. To do so:

-> Goto> modules > mod_mainmenu

-> Edit mod_mainmenu.xml and add the code <option value=”test_type”>test-type</option> like this:

<param name="menutype" type="mos_menu" default="" label="Menu Name" description="The name of the menu (default is mainmenu)" />
<param name="menu_style" type="list" default="list" label="Menu Style" description="The menu style">
<option value="list">List</option>
<option value="vert_indent">Legacy - Vertical</option>
<option value="horiz_flat">Legacy - Horizontal</option>
<option value="list_flat">Legacy - Flat List</option>
<option value="test_type">test-type</option>
</param>

And save the file. This will now show the name test-type in the drop down of the module manager menu manager along with already defined joomla 1.5 types.

2. Edit: helper.php

Next step involves editing helper.php in the modules >  mod_mainmenu folder.

In this file, we will define a case for the new custom type that we just defined in the menu type select drop down in the above step for Joomla! 1.5 administration module manager.

Goto the helper.php and find this part of code and enter after this code the part in bold below:

function render(&$params, $callback)
{
switch ( $params->get( 'menu_style', 'list' ) )
{
case 'list_flat' :
// Include the legacy library file
require_once(dirname(__FILE__).DS.'legacy.php');
mosShowHFMenu($params, 1);
break;
case 'horiz_flat' :
// Include the legacy library file
require_once(dirname(__FILE__).DS.'legacy.php');
mosShowHFMenu($params, 0);
break;
case 'vert_indent' :
// Include the legacy library file
require_once(dirname(__FILE__).DS.'legacy.php');
mosShowVIMenu($params);
break;

case 'test_type' :
// Include the legacy library file
require_once(dirname(__FILE__).DS.'legacy.php');
mosShowttMenu($params, 0);
break;

3. Edit: legacy.php

Now we will be editing the legacy.php in the mod_mainmenu folder of the modules folder. In legacy.php file, we will simply copy all of the code that is inside any previous menutype declaration and just rename the function to our own name and edit the code in it as we want like this:

Copy the function for horizonatal type there e.g.

/**
* Draws a horizantal style menu (very simple case)
*/
function mosShowHFMenu(& $params, $style = 0)
{
$menu = & JSite::getMenu();
$user = & JFactory::getUser();
//get menu items
.
.

}

and paste it just below it and just rename the function name from mosShowHFMenu to mosShowttMenu like this:

/**
* Draws a test type menu (very simple case)
*/
function mosShowttMenu(& $params, $style = 0)
{
$menu = & JSite::getMenu();
$user = & JFactory::getUser();
//get menu items
.
.

}

You can edit this copied function upto your code needs that how you want this new custom menu type to deliver the menu code.

Hope it helps, do let me know if you need any help regarding this or have any trouble in customizing it.

Exit mobile version