DrupalBin
Submit Code
About
Recent Posts
What is this?
display suite field group
Code
Code
Code
Code
Fix for UC Node Checkout - Base Product Title into Token
Code
Import a content type from a file.
Alteration to Trying to alter contact form to allow pre-selecting of cid
more
User login
Log in using OpenID:
What is OpenID?
Username:
*
Password:
*
Log in using OpenID
Cancel OpenID login
Create new account
Request new password
Tags
CCK
drupal
fapi
jquery
menu
module
php
simpletest
test
theme
user
views
more tags
Home
Fix for Fix for expanded menu overide for set MID - needs to collapse MID properly when not ative
View
Fix
June 25, 2010 - 10:14am — Anonymous
/**
* Implementation of theme_menu_item().
* Add active class and custom id to current menu item links.
*/
function
zen_menu_item
(
$mid
,
$children
=
''
,
$leaf
=
TRUE
)
{
// store a list of the menu items that are products
// use a static var so we only do this once.
static
$products
=
null
;
if
(
!
$products
)
{
$products
=
array
(
)
;
$products_mid
=
109
;
$products_item
=
menu_get_item
(
$products_mid
)
;
$products
[
$products_mid
]
=
$products_item
[
'path'
]
;
foreach
(
$products_item
[
'children'
]
as
$child_mid
)
{
$child
=
menu_get_item
(
$child_mid
)
;
// we want the paths because we have to check to see if one of them is active
$products
[
$child_mid
]
=
$child
[
'path'
]
;
}
}
$item
=
menu_get_item
(
$mid
)
;
// get current menu item
// decide whether to add the active class to this menu item
if
(
(
drupal_get_normal_path
(
$item
[
'path'
]
)
==
$_GET
[
'q'
]
)
// if menu item path...
||
(
drupal_is_front_page
(
)
&&
$item
[
'path'
]
==
'<front>'
)
)
{
// or front page...
$active_class
=
' active'
;
// set active class
}
else
{
// otherwise...
$active_class
=
''
;
// do nothing
}
// we only expand the products menu on the front page
// or when a product is selected.
// there is a special kind of action when we are on the product page itself.
$is_product
=
in_array
(
$_GET
[
'q'
]
,
$products
)
;
if
(
!
$children
||
(
!
$is_product
&&
!
drupal_is_front_page
(
)
&&
$mid
== 109
)
)
{
$is_expanded
=
false
;
}
else
{
$is_expanded
=
true
;
}
$attribs
=
isset
(
$item
[
'description'
]
)
?
array
(
'title'
=
>
$item
[
'description'
]
)
:
array
(
)
;
$replace
=
array
(
' '
,
'&'
)
;
$attribs
[
'id'
]
=
'menu-'
.
str_replace
(
$replace
,
'-'
,
strtolower
(
$item
[
'title'
]
)
)
;
return
'
<li class="'
.
(
$leaf
?
'leaf'
:
(
$is_expanded
?
'expanded'
:
'collapsed'
)
)
.
$active_class
.
'" id="'
.
$attribs
[
'id'
]
.
'">'
.
menu_item_link
(
$mid
)
.
$children
.
"</li>
\n
"
;
}
See Also:
dev site
expanded
menu
Submit Fix
Summary:
Tags:
Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Show summary in full view
/** * Implementation of theme_menu_item(). * Add active class and custom id to current menu item links. */ function zen_menu_item($mid, $children = '', $leaf = TRUE) { // store a list of the menu items that are products // use a static var so we only do this once. static $products = null; if (!$products) { $products= array(); $products_mid = 109; $products_item = menu_get_item($products_mid); $products[$products_mid] = $products_item['path']; foreach ($products_item['children'] as $child_mid) { $child = menu_get_item($child_mid); // we want the paths because we have to check to see if one of them is active $products[$child_mid] = $child['path']; } } $item = menu_get_item($mid); // get current menu item // decide whether to add the active class to this menu item if ((drupal_get_normal_path($item['path']) == $_GET['q']) // if menu item path... || (drupal_is_front_page() && $item['path'] == '<front>')) { // or front page... $active_class = ' active'; // set active class } else { // otherwise... $active_class = ''; // do nothing } // we only expand the products menu on the front page // or when a product is selected. // there is a special kind of action when we are on the product page itself. $is_product = in_array($_GET['q'], $products); if (!$children || (!$is_product && !drupal_is_front_page() && $mid == 109) ) { $is_expanded = false; } else { $is_expanded = true; } $attribs = isset($item['description']) ? array('title' => $item['description']) : array(); $replace = array(' ', '&'); $attribs['id'] = 'menu-'. str_replace($replace, '-', strtolower($item['title'])); return ' <li class="'. ($leaf ? 'leaf' : ($is_expanded ? 'expanded' : 'collapsed')) . $active_class .'" id="'. $attribs['id'] . '">' . menu_item_link($mid) . $children ."</li> \n"; }
Syntax highlighting mode:
ActionScript
ColdFusion
Diff
Drupal 5
Drupal 6
HTML
INI
Javascript
MySQL
PHP
Python
robots.txt
SQL
Text
Select the syntax highlighting mode to use.
See Also:
Order
Title:
URL:
-1
0
1
Title:
URL:
-1
0
1
Any links you'd like to have associated with the post (Drupal.org issue, Wikipedia article, etc).
File attachments
Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.
Attach new file:
The maximum upload size is
1 MB
. Only files with the following extensions may be uploaded:
jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp
.