$menu) { $blocks[$key]['info'] = t('CuteMenu: !name', array('!name' => $menu)); } return $blocks; case 'configure': $form = array(); $sql = "SELECT * FROM {cutemenu_block} WHERE menu_name = '%s'"; $db = db_query($sql, $delta); if ($db) { $block_info = db_fetch_object($db); } if (!$block_info) { $block_info = (object) array( 'hide_menu_without_submenus' => 0, 'top_menu_use_links' => 0, 'top_menu_use_css' => 0, ); } $form['hide_menu_without_submenus'] = array( '#type' => 'checkbox', '#title' => t('Hide menu entries without sub-menus.'), '#default_value' => $block_info->hide_menu_without_submenus, '#description' => t('Tell the system whether plain menus should be shown or not. By default, CuteMenu shows all top menus of the block.'), ); $form['top_menu_use_links'] = array( '#type' => 'checkbox', '#title' => t('Top menu buttons use links.'), '#default_value' => $block_info->top_menu_use_links, '#description' => t('When checked the top menus are turned into links.'), ); $form['top_menu_use_css'] = array( '#type' => 'checkbox', '#title' => t('Top menu buttons use CuteMenu Stylesheet.'), '#default_value' => $block_info->top_menu_use_css, '#description' => t('Whether the top menus are left alone (Drupal default) or assigned the CuteMenu style.'), ); return $form; case 'save': $sql = "UPDATE {cutemenu_block} SET hide_menu_without_submenus = %d, top_menu_use_links = %d, top_menu_use_css = %d WHERE menu_name = '%s'"; db_query($sql, $edit['hide_menu_without_submenus'], $edit['top_menu_use_links'], $edit['top_menu_use_css'], $edit['delta']); if (db_affected_rows() == 0) { $sql = "INSERT INTO {cutemenu_block} (menu_name, hide_menu_without_submenus, top_menu_use_links, top_menu_use_css) VALUES ('%s', %d, %d, %d)"; db_query($sql, $edit['delta'], $edit['hide_menu_without_submenus'], $edit['top_menu_use_links'], $edit['top_menu_use_css']); } break; case 'view': $block['content'] = _cutemenu_build($delta); if ($block['content']) { $block['subject'] = t('CuteMenu: !name', array('!name' => $delta)); return $block; } break; } } function _cutemenu_build($menu_name) { // DO NOT SPECIFY AN ITEM, or only the root items // will be shown... (i.e. no dropdown) $items = menu_tree_all_data($menu_name, NULL); $sql = "SELECT * FROM {cutemenu_block} WHERE menu_name = '%s'"; $db = db_query($sql, $menu_name); if ($db) { $block_info = db_fetch_object($db); } if (!$block_info) { $block_info = (object) array( 'hide_menu_without_submenus' => 0, 'top_menu_use_links' => 0, 'top_menu_use_css' => 0, ); } $hide_menus_without_submenus = $block_info->hide_menu_without_submenus != 0; $top_menu_use_links = $block_info->top_menu_use_links != 0; $top_menu_use_css = $block_info->top_menu_use_css == 0; $output = ""; if ($top_menu_use_css) { $output = '
'; } return " \n"; } function _cutemenu_menu_link($item, $link, $div = TRUE) { // fix the attributes as required $localized_options = $item['link']['localized_options']; if ($item['link']['in_active_trail']) { $classes = ''; if (!empty($localized_options['attributes']['class'])) { $classes = $localized_options['attributes']['class'] . ' '; } $classes .= 'active-trail'; $localized_options['attributes']['class'] = $classes; } // use t() so one can do a translation of the link name on the fly (with gettext() functionality) $title = t('!link_name', array('!link_name' => check_plain($item['link']['title']))); if ($link) { // generate and return the link if (is_array($localized_options['attributes'])) { $opt_attr = $localized_options['attributes']; if (!empty($opt_attr['class'])) { $opt_attr['class'] .= ' cutemenu-link'; } else { $opt_attr['class'] = 'cutemenu-link'; } } else { $opt_attr = array( 'class' => 'cutemenu-link', ); } $attr = ''; foreach ($opt_attr as $name => $value) { $attr .= ' ' . $name . '="' . check_plain($value) . '"'; } // transform the path to the corresponding alias $href = drupal_get_path_alias($item['link']['href']); return '' . $title . ''; } if ($div) { return ' '; } return $title; } /** * Implementation of hook_form_alter() */ function cutemenu_form_alter(&$form, $form_state, $form_id) { switch ($form_id) { case 'menu_edit_item': // make sure the submit button appears after our fieldset $form['submit']['#weight'] = 1; $sql = "SELECT * FROM {cutemenu_menu_item} WHERE mlid = %d"; $menu_item_info = NULL; if (isset($form['menu']['#item']['mlid']) && $form['menu']['#item']['mlid']) { $db = db_query($sql, $form['menu']['#item']['mlid']); if ($db) { $menu_item_info = db_fetch_object($db); } } if (!$menu_item_info) { $menu_item_info = (object) array('menu_role' => 'normal'); } $form['cutemenu'] = array( '#type' => 'fieldset', '#title' => t('CuteMenu settings'), '#description' => t('Menu Item specific setup for CuteMenu.'), '#collapsible' => TRUE, '#collapsed' => $menu_item_info->menu_role == 'normal', // hide by default, unless not normal ); $form['cutemenu']['menu_role'] = array( '#type' => 'radios', '#title' => t('Menu Item Role'), '#options' => array('normal' => t('Normal Menu Item'), 'header' => t('Header, use destination node as the Header'), 'footer' => t('Footer, use destination node as the Footer'), 'title' => t('Title, use destination node as a menu Title')), '#default_value' => $menu_item_info->menu_role, '#description' => t('Choose how the item is to be used. By default, CuteMenu expects the items to be Normal.'), ); $form['#submit'][] = '_cutemenu_menu_edit_item_submit'; break; } } /** * hook_submit() * Submit for menu edit item. */ function _cutemenu_menu_edit_item_submit($form, &$form_state) { if ($form_state['submitted']) { $mlid = $form_state['values']['menu']['mlid']; if ($mlid) { $sql = "UPDATE {cutemenu_menu_item} SET menu_role = '%s' WHERE mlid = %d"; db_query($sql, $form_state['values']['menu_role'], $mlid); if (db_affected_rows() == 0) { $sql = "INSERT INTO {cutemenu_menu_item} (mlid, menu_role) VALUES (%d, '%s')"; db_query($sql, $mlid, $form_state['values']['menu_role']); } } else { // in this case we just cannot save anything, too bad drupal_set_message(t('The menu link identifier was not defined on Submit in CuteMenu. You are most certainly adding a new menu item. For this feature to work when adding a menu item, you must apply the patch defined in node #326210. That patch is included in this module for that purpose.'), 'error'); } } } // vim: ts=2 sw=2 et syntax=php