Panel and the default tabs

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
leuski's picture

I have a question about how to modify the default view of a panel for authorized users. I have a content type: project. I have a view that lists all the projects. I have a panel page that contains that view. Now, if an authenticated user comes to this page, at the top of the page he sees the the title ("Projects") and two default tabs: "View" and "Edit Panel". I want to add another tab "Add Project" to that row that would be linked to the node/add/project page. Is this possible? How do I do that? I'm running drupal-6.16 and panels-6.x-3.3. Thank you for your help.

Comments

That's not really a Panels

merlinofchaos's picture

That's not really a Panels question, that's a question about the Drupal menu system. The answer is that it's ridiculously hard to manipulate those tabs. :/

Ah! Thank you for pointing me

leuski's picture

Ah! Thank you for pointing me in the right direction. So it's a menu. It's the panel that creates that menu, is it not? I guess, from your comment it's not possible to modify the menu from the interface and one has to write some php code and insert it somewhere, right? Will I be better off just creating my own menu? Can I add a menu of my own to a panel? Is there a way to switch off the default tabs then?

On removing the default tabs

montesde's picture

I needed to remove the default tabs too and had to plow through the forums to find an answer. I used this to remove the tabs from a content type 'project' among others. Paste this in your template.php file. Just replace theme with your theme and project with whatever your content type is if this is for a specific content type. This works for other tabs as well, just add them to be removed. You can use different logic too if you want to be specific about where tabs get removed.

<?php
function phptemplate_preprocess(&$variables, $hook) { 
 
$nid = str_replace('page-node-','',$variables['template_files'][1]);
 
$node = node_load($nid);

  if(
$hook == 'page' &&  $node->type == 'project') {
   
theme_removetab('Edit', $variables);
   
theme_removetab('View', $variables);
   
theme_removetab('Outline', $variables);
  }

return
$variables;
}

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

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

Perfect!

MAds's picture

montesde, after hours of searching and trial and error, this worked perfect for me!

Thanks!

Great! This really helped me

spoit's picture

Great! This really helped me out here! I first tried to accomplish trough hook_menu_alter, but that didn't go anywhere. Additionally, I

  • moved the preprocessing to the theme_preprocess_page hook for lighter load (although I doubt it makes much different, it just feels cleaner)
  • wrapped the tab names in the t() function so that that translated tabs get removed too

<?php
function phptemplate_preprocess_page(&$variables, $hook) {
   
$nid = str_replace('page-node-','',$variables['template_files'][1]);
   
$node = node_load($nid);

    if(
$node->type == 'project') {
     
theme_removetab(t('Edit'), $variables);
     
theme_removetab(t('View'), $variables);
     
theme_removetab(t('Outline'), $variables);
    }
}
?>

It's surely an useful tip.

jcisio's picture

It's surely an useful tip. Bookmarking...

How can this be done for

infines's picture

How can this be done for Drupal 7?

Panels

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week