You are here

function _popup_menuelement in Popup 6.x

Same name and namespace in other branches
  1. 8 includes/popup.util.inc \_popup_menuelement()
  2. 7 includes/popup.util.inc \_popup_menuelement()
  3. 7.x includes/popup.util.inc \_popup_menuelement()

Recursively generates popup menus

1 call to _popup_menuelement()
_popup_menu in includes/popup.api.inc

File

includes/popup.util.inc, line 222

Code

function _popup_menuelement($menu, $attributes, $level = 0) {
  global $user;
  $body = '';
  $title = $attributes['title'] ? $attributes['title'] : $menu['link']['title'];
  $link = drupal_get_path_alias(str_replace('%', $user->uid, $menu['link']['link_path']));
  if ($menu['link']['has_children'] && is_array($menu['below'])) {
    $children = _popup_menuelement_visible_items($menu['below']);
    $child_attributes = _popup_menuelement_child_attribs($attributes);
    if ($attributes['flat']) {
      $child_attributes['expand'] = $attributes['expand'];
      $child_attributes['origin'] = $attributes['origin'];
    }
    foreach ($children as $child) {
      $body .= _popup_menuelement($child, $child_attributes, $attributes['flat'] ? $level : $level + 1);
    }
    $attributes['classes']['body'][] = 'popup-menu-branch-body-' . _popup_title_to_key($title);
    $attributes['classes']['element'][] = 'popup-menu-branch-element-' . _popup_title_to_key($title);
    $attributes['classes']['element'][] = 'popup-menu-branch';
    $attributes['classes']['title'][] = 'popup-menu-branch-title';
    $attributes['classes']['title'][] = 'popup-menu-item';
    $attributes['classes']['title'][] = 'popup-menu-item-' . _popup_title_to_key($title);
    $attributes['link'] = $link;
    if ($level > 0) {
      $attributes['classes']['element'][] = 'popup-menu-child';
    }
    return $attributes['flat'] ? '<div class="popup-menu-flat' . ($attributes['inline'] ? ' popup-menu-inline' : ' popup-menu-block') . ' popup-style-' . _popup_title_to_key($attributes['style']) . '">' . $body . '</div>' : popup_element($title, $body, $attributes);
  }
  else {
    return l('<span>' . $title . '</span>', $link, array(
      'html' => TRUE,
      'attributes' => array(
        'class' => 'popup-menu-item popup-menu-leaf-title' . ($attributes['activate'] == 'hover' ? ' activate-hover' : '') . ' popup-menu-item-' . _popup_title_to_key($title),
      ),
    ));
  }
}