User login

Where in the theme are the tabs printed / giving tabs to admins only

On giving View, Edit, Revision, etc. tabs to administrators only.

In Drupal, tabs are not printed by the node, but by the page. On the one hand, since views and administrative pages and anything else you can think of can have tabs, this makes sense. But on the other hand every node can have

But in any case, if you're looking to change the presentation of tabs somehow (or as in our case, restore them to a theme design from which they had been removed), you will find the place to look is not node.tpl.php but page.tpl.php.

For instance, line 42 from bluemarine's page.tpl.php:

        <div class="tabs"><?php print $tabs ?></div>

(Special _phptemplate_variables pseudo hook function can add to and modify variables headed to a template. The one below styles itself after Garland's.)

<?php
/**
 * Modeled on Garland's implementation of _phptemplate_variables.
 * Personally I think I like using the switch statement.
 */
function _phptemplate_variables($hook, $vars = array()) {
  if ($hook == 'page') {
    // if the user does not have basic administration permissions,
    // do not show any tabs (backwards compatibility with theme)
    if (!user_access('access administration pages')) {
      $vars['tabs'] = '';
    }
    return $vars;
  }
  return array();
}
?>

Resolution

Searched words: 
Drupal tabs local tasks where printed by theme? phptemplate_variables page phptemplate node page tabs give tabs to admins only

Comments

Made display of the div conditional

For this unusual use where tabs are eliminated for non-administrator users, we make display of the tabs div itself conditional on there being tabs to display:

      <?= $above_content; ?>
      <?php if ($tabs) { ?>
        <div class="tabs"><?php print $tabs; ?></div>
      <?php } ?>
      <?=$content?>

Removing tabs for non-admins

Hey Ben,

Thanks for this tutorial, its really cool. But me not being a php expert, I'm having trouble integrating this snippet into my theme. This is because my template.php file already has function _phptemplate_variables declared using a switch statement that allows certian pages to have different background colors. I cant re-declare the variables, so I'm looking to see how I can integrate this statement into the statement declaring the _phptemplate_variables. I've provided an example of how the code is written into my template file.

function _phptemplate_variables($hook, $vars = array())
{
switch($hook)
{
case 'page':

if (module_exists('path'))
{
$alias = drupal_get_path_alias($_GET['q']);

$suggestions = array();
$template_filename = 'page';

foreach (explode('/', $alias) as $path_part)
{
$template_filename = $template_filename . '-' . $path_part;
$suggestions[] = $template_filename;
}

$vars['template_files'] = $suggestions;
}

break;
}
return $vars;

}

I tried adding just the if statement benearth the $vars['template_files']=$suggestions; statement, and returning the array at the bottom beneath return $vars; , but that didn't work.

Would you have any thoughts on how to remove tabs for non-admins on pages that already have that function and variables declared for other purposes?

Many thanks!

-Cam

Shouldn't have to do anything for non-admins

Tabs should not print at all for non-admins, people don't see tabs they don't have access to, so simply turning off permissions for viewing revisions, say, may take care of it.

For the general issue of adding to the _phptemplates_variables, yes, just add case: clauses or switch statements to the function.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.