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

Joomla! provides four menu types by default

  • list
  • legacy_horizantal
  • legacy_verticaljoomla
  • legacy_flat

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.

hire best wordpress php css developer
Need Help? Hire me now!
I can help you in anything related to webdevelopment, including: HTML, CSS, PHP & MySql, WordPress (plugins & themes development, others), regular expressions, server management, etc.

21 comments on “How to add new custom menu type in Joomla! 1.5 tutorial

  1. Cool what you blogged about realli made my day! (ok i know u must think im a crazy haha!) Sorry for my poor english!

  2. Thanks for the information because I have spent several days trying to find a a way to modify the legacy menu types to create a drop down select menu that works with noixacl. I have previously used “extended menu” module to create a custom select list but his module does not work with NoixACL and there are no adapters for it that I can find.

    I wonder, could anyone please assist and help me out.

    I would need the required code for legacy.php to deliver a menu that creates a standard javascript type form pull down selection menu.

    If you could help that would be much appreciated.

    1. it will definitely be a pleasure to help you out!

      Please let me know any example webpage so that i can have a clear idea of what type of menu you want to be generated.

  3. Something similar to this but this does not create working links with the present blank option value. What should go inside the option value to create working links?

    function mosShowDTMenu(& $params, $style = 0)
    {
    $menu = & JSite::getMenu();
    $user = & JFactory::getUser();

    //get menu items

    //open form
    echo ”;
    echo ”;
    echo ‘Select Class Tools’;
    //generate links

    $menuclass = ‘mainlevel’ . $params->get(‘class_sfx’);
    $lang =& JFactory::getLanguage();

    $rows = $menu->getItems(‘menutype’, $params->get(‘menutype’));
    foreach ($rows as $row)
    {
    if ($row->access get(‘aid’, 0)) {
    echo ” . mosGetMenuLink($row, 0, $params);
    // echo ” . mosGetMenuLink($row, 0, $params);
    }
    }

    echo ”;
    echo ‘ ‘;
    //end form

    }

    //END CUSTOM CODE

    1. if the update includes update to mod_mainmenu, then it will be overwritten

      you can backup the mod_mainmenu folder and replace it back once update has been done.

        1. yes it is possible

          you need to rename the folder and file names from mainmenu to custommenu etc and also edit the xml file to change all the file and item names in it

          once done that, you need to “install” this new module from extension manager and then use it

          Please note, this is possible, but it may still conflict with the existing mainmenu module as functions and classes being used by them would be same. If you want to do so, it may need some work to rename all the classes being used and fix the conflicts.

  4. I have previously used “extended menu” module to create a custom select list but his module does not work with NoixACL and there are no adapters for it that I can find.

Leave a Reply

Your email address will not be published.