Actions

API16

JHtmlMenu/menuitems

From Joomla! Documentation

< API16:JHtmlMenu
Revision as of 21:58, 13 May 2013 by JoomlaWikiBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Returns an array of menu items groups by menu.

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

static menuitems($config=array())
Parameter Name Default Value Description
$config array() An array of configuration options.

Returns

array

Defined in

libraries/joomla/html/html/menu.php

Importing

jimport( 'joomla.html.html.menu' );

Source Body

public static function menuitems($config = array())
{
        if (empty(self::$items))
        {
                $db = JFactory::getDbo();
                $db->setQuery(
                        'SELECT menutype As value, title As text' .
                        ' FROM #__menu_types' .
                        ' ORDER BY title'
                );
                $menus = $db->loadObjectList();
 
                $query  = $db->getQuery(true);
                $query->select('a.id AS value, a.title As text, a.level, a.menutype');
                $query->from('#__menu AS a');
                $query->where('a.parent_id > 0');
                $query->where('a.type <> '.$db->quote('url'));
 
                // Filter on the published state
                if (isset($config['published'])) {
                        $query->where('a.published = '.(int) $config['published']);
                }
 
                $query->order('a.lft');
 
                $db->setQuery($query);
                $items = $db->loadObjectList();
 
                // Collate menu items based on menutype
                $lookup = array();
                foreach ($items as &$item) {
                        if (!isset($lookup[$item->menutype])) {
                                $lookup[$item->menutype] = array();
                        }
                        $lookup[$item->menutype][] = &$item;
 
                        $item->text = str_repeat('- ',$item->level).$item->text;
                }
                self::$items = array();
 
                foreach ($menus as &$menu) {
                        self::$items[] = JHtml::_('select.optgroup',    $menu->text);
                        self::$items[] = JHtml::_('select.option', $menu->value.'.0', JText::_('COM_MENUS_ADD_TO_THIS_MENU'));
 
                        if (isset($lookup[$menu->value])) {
                                foreach ($lookup[$menu->value] as &$item) {
                                        self::$items[] = JHtml::_('select.option', $menu->value.'.'.$item->value, $item->text);
                                }
                        }
                }
        }
 
        return self::$items;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />