Monday, July 23, 2007

Druapl Mania

I'm working on getting Drupal to work as a CMS for BYU. I've learned a lot in the last few weeks of work. Right now I'm working on the menuing system. We want drop down menus. I built one from scratch using the yui, but alas, it wasn't cross-browser compatible, which really stinks. So now I'm trying out using yui's menu class as the base. I'm over-ridding some of Drupal's themeing functions to get it to work. Here's what I have so far:
 /**
* Generate the HTML for a menu tree.
*
* @param $pid
* The parent id of the menu.
*
* @ingroup themeable
*/
function byu1_menu_tree($pid = 1, $level = 0) {
if ($tree = byu1_menu_tree_improved($pid, $level)) {
return "\n
\n
\n
    \n". $tree ."\n
\n
\n";
}
}


/**
* Returns a rendered menu tree.
*
* @param $pid
* The parent id of the menu.
*/
function byu1_menu_tree_improved($pid = 1, $level = 0) {
$menu = menu_get_menu();
$output = '';

if (isset($menu['visible'][$pid]) && $menu['visible'][$pid]['children']) {
$num_children = count($menu['visible'][$pid]['children']);
for ($i=0; $i < $num_children; ++$i) { $i == 0 ? $level++ : ''; $mid = $menu['visible'][$pid]['children'][$i]; $type = isset($menu['visible'][$mid]['type']) ? $menu['visible'][$mid]['type'] : NULL; $children = isset($menu['visible'][$mid]['children']) ? $menu['visible'][$mid]['children'] : NULL; $extraclass = $i == 0 ? 'first' : ($i == $num_children-1 ? 'last' : ''); $output .= theme('menu_item', $mid, menu_in_active_trail($mid) || ($type & MENU_EXPANDED) ? theme('menu_tree', $mid, $level) : '', count($children) == 0, $extraclass, $level); $i == $num_children - 1 ? $level-- : ''; } } return $output; } /** * Generate the HTML output for a single menu item. * * @param $mid * The menu id of the item. * @param $children * A string containing any rendered child items of this menu. * @param $leaf * A boolean indicating whether this menu item is a leaf. * * @ingroup themeable */ function byu1_menu_item($mid, $children = '', $leaf = TRUE, $extraclass = '', $level) { return '
  • '. menu_item_link($mid, TRUE, $extraclass) . $children ."
  • \n";
    }

    No comments:

    Pyjamas