You are here

function simplemenu_tree_output in SimpleMenu 6.2

Same name and namespace in other branches
  1. 6 simplemenu.module \simplemenu_tree_output()

Render the necessary markup from the tree array. This is largely based on theme_item_list(), without the extra markup.

Parameters

$tree: Array of items as expected in theme_item_list().

1 call to simplemenu_tree_output()
simplemenu_get_menu in ./simplemenu.module
Render an HTML list of links for a given menu.

File

./simplemenu.module, line 297
Creates a simplemenu.

Code

function simplemenu_tree_output($items, $attributes = array()) {
  if (!empty($items)) {
    $output .= '<ul' . drupal_attributes($attributes) . '>';
    $num_items = count($items);
    foreach ($items as $i => $item) {
      $attributes = array();
      $children = array();
      if (is_array($item)) {
        foreach ($item as $key => $value) {
          if ($key == 'data') {
            $data = $value;
          }
          elseif ($key == 'children') {
            $children = $value;
          }
          else {
            $attributes[$key] = $value;
          }
        }
      }
      else {
        $data = $item;
      }
      if (count($children) > 0) {
        $data .= simplemenu_tree_output($children);

        // Render nested list
        $attributes['class'] = empty($attributes['class']) ? 'expanded' : $attributes['class'] . ' expanded';
      }
      $output .= '<li' . drupal_attributes($attributes) . '>' . $data . "</li>\n";
    }
    $output .= "</ul>\n";
  }
  return $output;
}