[development] Fwd: How to add comment under menu items

Cédric Joubert cedjoubert at gmail.com
Wed Mar 17 08:28:54 UTC 2010


I'm surprised, i did not receive any response... while i am sure, the code
below is not very nice ;-)

any idea to help me do that in a good and correct Drupal way please ?


---------- Forwarded message ----------
From: Cédric Joubert <cedjoubert at gmail.com>
Date: 2010/3/6
Subject: How to add comment under menu items
To: development at drupal.org


I'm new on Drupal and I would like to know how can I make properly such
comment on items Menu please ?
 -> each first row is a link and each 2nd row is a comment...

- Menu 1
  (my explanation)

- Menu 2
  (other explanation ...)

The only solution i've found is to do that (below)... but i'm sure it's not
a property way...
- the only constraint i have is to have the abbility to get the Description
field in the underlying menu to display a dynamic comment.
but actually, the only trick I've found to get the Description is to parse
the HTML string to retrieve the "title" tag to get my text.
Not very cool, i think...
- actually, to determine the underlying nodes menu, i'm testing her names...
is there another way to do that ?

Can you help me please ?


function myTheme_menu_item($link, $has_children, $menu = '',
$in_active_trail = FALSE, $extra_class = NULL) {
  $class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
  if (!empty($extra_class)) {
    $class .= ' '. $extra_class;
  if ($in_active_trail) {
    $class .= ' active-trail';
  $css_id = strip_tags($link);

  // test the node for which i want to add comment
  if (stripos($link, 'MyMenu1') > 0 || stripos($link, 'MyMenu2') > 0) {
    $rec = 'title="';
    $i = stripos($link, $rec);
    if ($i > 0) {
       $j = strpos($link, '"', $i+strlen($rec));
       if ($j > 0)
         $title = substr($link, $i+strlen($rec), $j-$i-strlen($rec));

  $title = ($title != "") ? '<div
class="views-field-created"><h0>&nbsp;&nbsp;&nbsp;&nbsp;[' . $title .
']</h0></div>' : '';
  return '<li class="'. $class .'">'. $link . $menu ."</li>\n" . $title;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20100317/2b4eb349/attachment.html 

More information about the development mailing list