I'm new to drupal and not sure if this is done "the drupal way" but i needed a collapsible version of the menuwriter block... So i added this:


function menuwriter_block_tree_output($tree, $level=1) {
  $output = '<ul id="menuwriter_block">';
  $items = array();

  // Pull out just the menu items we are going to render so that we 
  // get an accurate count for the first/last classes.
  foreach ($tree as $data) {
    if (!$data['link']['hidden']) {
      $items[] = $data;
    }
  }

  $num_items = count($items);
  foreach ($items as $i => $data) {
    $extra_class = NULL; 
    if ($i == 0) { 
      $extra_class = 'first';
    }
    if ($i == $num_items - 1) {
      $extra_class = 'last'; 
    }

      $link = theme_menuwriter_block_item_link( $data['link'], $level);

    if ($data['below']) {
      $output .= theme('menu_item', $link, $data['link']['has_children'], menuwriter_block_tree_output($data['below'], '2'), $data['link']['in_active_trail'], $extra_class);
    }
    else {
      $output .= theme('menu_item', $link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class);
    }
  }
  $output .= '</ul>';
  return $output ;
}


How can i do changes like this without loosing the possibility to update?

regards Volkan

Comments

muschpusch’s picture

I'm stupid... That was the originial code...

This is the modified version:


function menuwriter_block_tree_output($tree, $level=1) {
  $output = '<ul id="menuwriter_block">';
  $items = array();

  // Pull out just the menu items we are going to render so that we 
  // get an accurate count for the first/last classes.
  foreach ($tree as $data) {
    if (!$data['link']['hidden']) {
      $items[] = $data;
    }
  }

  $num_items = count($items);
  foreach ($items as $i => $data) {
    $extra_class = NULL; 
    if ($i == 0) { 
      $extra_class = 'first';
    }
    if ($i == $num_items - 1) {
      $extra_class = 'last'; 
    }

      $link = theme_menuwriter_block_item_link( $data['link'], $level);

    // Next two lines modified
    $current_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    if ($data['below'] && $current_url==$data['link']['link_path']) {
      $output .= theme('menu_item', $link, $data['link']['has_children'], menuwriter_block_tree_output($data['below'], '2'), $data['link']['in_active_trail'], $extra_class);
    }
    else {
      $output .= theme('menu_item', $link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class);
    }
  }
  $output .= '</ul>';
  return $output ;
}

behindthepage’s picture

Hi Volkan,

All the features of Menuwriter have been merged into Signwriter now (or a version soon to be released) so menuwriter will not be upgraded or improved (so hack away).

You may also be interested in Cufon which is a Javascript image for text replacement with the rendering done in the browser. Check out "Cufon" on Google. There is a cufon module and adt_basetheme has cufon incorporated in it as well.

Regards
Geoff

behindthepage’s picture

Status: Active » Closed (fixed)