Some Drupal menu notes

This is just some notes, you wont get anything out of it :-)

http://drupal.org/node/68792, tabs
http://drupal.org/node/483324, menu
http://drupal.org/node/68792, menu

<?php
/**
* If the user isn't an admin, or the original administrative user,
* remove the "Edit" tab for the "note" nodes in the my_garland theme.
*/
function phptemplate_preprocess(&$variables, $hook) {
    global
$user;
    if(
$hook == 'page' && !in_array('admin',array_values($user->roles)) && $user->uid != 1){
       
$nid = str_replace('page-node-','',$variables['template_files'][1]);
       
$node = node_load($nid);
        if(
$node->type == 'note'){
           
my_garland_removetab('Edit', $variables);
        }
    }
    return
$variables;
}
?>



function r2d2_variables($hook, $vars = array()) {

  if ($hook == 'page') {
    r2d2_removetab('address book', $vars);
    // add additional lines here to remove other tabs.
  }

  return $vars;
}

function r2d2_removetab($label, &$vars) {
  $tabs = explode("\n", $vars['tabs']);
  $vars['tabs'] = '';

  foreach ($tabs as $tab) {
    if (strpos($tab, '>' . $label . '<') === FALSE) {
      $vars['tabs'] .= $tab . "\n";
    }
  }
}

function phptemplate_menu_local_task($link, $active = FALSE) {
  if ( strpos($link,'search') ) {
    return '';
  }    else if ( strpos($link,'imce') ) {
    return '';
  } else {
      return '<li '. ($active ? 'class="active" ' : '') .'>'. $link ."</li>\n";
  }
}

function r2d2_menu_alter(&$items) {
//NOT IN RUNTIME
  // Removing certain local navigation tabs that are either undesired or need to be custom relocated.

  // Set these tabs to MENU_CALLBACK, so they still register the path, but just don't show the tab:
  /*$items['distribution/%/huffra'] = array(
'title' => 'Huffra',
'type' => MENU_LOCAL_TASK,
'weight' => 3,
'page callback' => 'r2d2_distribution_footer',
'page arguments' => array(1),
'access arguments' => array('access r2d2'),

);*/

  // Fully unset these tabs and their paths, don't want them at all. This breaks the path as well:
// unset($items['distribution/%/jabba']);
}


<?php
function _phptemplate_variables($hook, $vars = array()) {

  if (
$hook == 'page') {
   
yourthemename_removetab('address book', $vars);
   
// add additional lines here to remove other tabs.
 
}

  return
$vars;
}

function
yourthemename_removetab($label, &$vars) {
 
$tabs = explode("\n", $vars['tabs']);
 
$vars['tabs'] = '';

  foreach (
$tabs as $tab) {
    if (
strpos($tab, '>' . $label . '<') === FALSE) {
     
$vars['tabs'] .= $tab . "\n";
    }
  }
}
?>



<?php
// $Id: remove_tabs.module

/**
* Set up a new permission for the module.
* Grant access under admin -> user management -> permissions
*/
function remove_tabs_perm() {
  return array(
'view hidden tabs');
}

/**
* Implementation of hook_menu_alter().
* Remember to clear the menu cache after adding/editing this function.
*/
function remove_tabs_menu_alter(&$items) {
$items['node/%node/track']['access callback'] = 'user_access';
$items['node/%node/track']['access arguments'] = array('view hidden tabs');

$items['user/%user/view']['access callback'] = 'user_access';
$items['user/%user/view']['access arguments'] = array('view hidden tabs');

$items['user/%user/track']['access callback'] = 'user_access';
$items['user/%user/track']['access arguments'] = array('view hidden tabs');

$items['search/user']['access callback'] = 'user_access';
$items['search/user']['access arguments'] = array('view hidden tabs');
}
?>
Knowledge keywords: