API15:JHTMLMenu/linkoptions
From Joomla! Documentation
Description
Build the multiple select list for Menu Links/Pages
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
linkoptions($all=false, $unassigned=false)
| Parameter Name | Default Value | Description |
|---|---|---|
| $all | false | |
| $unassigned | false |
Defined in
libraries/joomla/html/html/menu.php
Importing
jimport( 'joomla.html.html.menu' );
Source Body
function linkoptions( $all=false, $unassigned=false )
{
$db =& JFactory::getDBO();
// get a list of the menu items
$query = 'SELECT m.id, m.parent, m.name, m.menutype'
. ' FROM #__menu AS m'
. ' WHERE m.published = 1'
. ' ORDER BY m.menutype, m.parent, m.ordering'
;
$db->setQuery( $query );
$mitems = $db->loadObjectList();
$mitems_temp = $mitems;
// establish the hierarchy of the menu
$children = array();
// first pass - collect children
foreach ( $mitems as $v )
{
$id = $v->id;
$pt = $v->parent;
$list = @$children[$pt] ? $children[$pt] : array();
array_push( $list, $v );
$children[$pt] = $list;
}
// second pass - get an indent list of the items
$list = JHTMLMenu::TreeRecurse( intval( $mitems[0]->parent ), '', array(), $children, 9999, 0, 0 );
// Code that adds menu name to Display of Page(s)
$mitems_spacer = $mitems_temp[0]->menutype;
$mitems = array();
if ($all | $unassigned) {
$mitems[] = JHTML::_('select.option', '<OPTGROUP>', JText::_( 'Menus' ) );
if ( $all ) {
$mitems[] = JHTML::_('select.option', 0, JText::_( 'All' ) );
}
if ( $unassigned ) {
$mitems[] = JHTML::_('select.option', -1, JText::_( 'Unassigned' ) );
}
$mitems[] = JHTML::_('select.option', '</OPTGROUP>' );
}
$lastMenuType = null;
$tmpMenuType = null;
foreach ($list as $list_a)
{
if ($list_a->menutype != $lastMenuType)
{
if ($tmpMenuType) {
$mitems[] = JHTML::_('select.option', '</OPTGROUP>' );
}
$mitems[] = JHTML::_('select.option', '<OPTGROUP>', $list_a->menutype );
$lastMenuType = $list_a->menutype;
$tmpMenuType = $list_a->menutype;
}
$mitems[] = JHTML::_('select.option', $list_a->id, $list_a->treename );
}
if ($lastMenuType !== null) {
$mitems[] = JHTML::_('select.option', '</OPTGROUP>' );
}
return $mitems;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
Code Examples