views:

75

answers:

4

Can I hide the

Edit | View

tabs on top of each node ?

I've searched for this option in theme settings (both global and standard theme but I couldn't find it).

I still want to be able my customer to edit / administer content, so I cannot just remove the permission for it.

thanks

A: 

I use the following in template.php by theme (which is perhaps a little hacky, I feel I should be considering unsetting $tabs instead):

function THEME_NAME_menu_local_tasks() {
  return '';
}

Or you could ommit:

if ($tabs) echo $tabs;

from your page.tpl.php...

CitrusTree
You should never change functionality with a theme. That is bad practice that will, at some point, lead to problems. It is "just not right coding practice".
berkes
I agree to some extent, but the OP does not want to affect the functionality, they want the links not to show, which to me is a theme issue.
CitrusTree
But "not showing the links" is similar to "affecting the functionality". Why else do you want to hide some interface-item that has a clear functionality attached?
berkes
I don't believe it is. The OP asked simply "how do I hide the links" - but still wants to allow his customer to be able to edit the content (or view it!) - so what functionality are you suggesting should be removed? :0)
CitrusTree
Thanks for answering. I actually want the customer to edit the pages only from back-end, and not using the tabs link in the front-end. So, I want the functionality but not in the front-end.
Patrick
However, removing $tabs from the template is too general solution. I only want to remove "Edit and View" and not all tabs (i.e. user login page | create account). Maybe I should go with css rather than php ?
Patrick
I'm off now, but this might help:http://drupal.org/node/379792
CitrusTree
+1  A: 

View and Edit are functional features. They have a reason for being there.

The best way to "remove" them, is to "remove" that functionality alltogether. After all: why remove the interface of a piece of functionality, but not the functionality itself? Besides, simply not printing the tabs, does not remove the url endpoints. In other words: if you don't print the edit tab, people can still access the edit page.

Again: best is to remove that functionality: The fact that you don't want the edit tab, sounds as if you don't want the edit functionality for certain users. If so, then just remove that permission for that role. That is all. The tabs will be gone.

If, however, you simply wish to display these tabs differently, Drupal is your friends. As you may have noticed, they are called local tasks and not tabs. That is because the theme decides how to render them: The theme is the thing that decides to show them as tabs.

Simply override the theme_menu_local_tasks() to create your own HTML for the "local-tasks". And in your page-tpl, simply move the $tabs variable around to a place, where you want them.

But again: Don't try to change the behavior of the app, by removing interface-elements. That is not the right thing to do: you should change the behavior, in order to change the behavior :)

berkes
The OP does not want to remove the functionality, as explicitly stated - just hide the links.
CitrusTree
The title of the question says _disable_, and the question asks for hiding the links. In both the cases, the result would be that nobody would be able to edit a node, which is a functional feature. If there is the need to hide the edit link, then it is possible to not give the permission to edit a content type to some rules. I don't think that unconditionally hide the edit link (which would mean to hide it even to the user #1) would be a good idea. To me, it seems the question is asked because a misunderstanding of how Drupal works.
kiamlaluno
Whether the title says disable or hide, it still refers to the [tabs] - not the functionality. Whether the tabs should be hidden, or not, is not the question, and nor is whether the functionality should therefore be removed - the question is how the links are disabled / hidden etc. I'm sure you agree that in some cases we do things which are not 'correct' in our opinions, for example a client insisting these tabs are hidden for their own reasons. Whether the reason is this, or another reason, I see no valid argument that states these tabs must stay if the functionality still exists.
CitrusTree
"the result would be that nobody would be able to edit a node"How so? what about /admin/content/node ?If you remove permission in order to hide the edit link, the user cannot edit from here either... Again, the OP stated the user in question should still be able to edit the content.
CitrusTree
I'm sorry "disabling" was not the correct word. I meant hiding the links, and keep the functionality enabled.
Patrick
Not all users have access to `/admin/content/node`; removing those tabs would not help an authenticated user, who should manually write the link to the edit page. If the purpose is to hide the tabs to show the link in a different way, that is fine; it's not fine to remove the tabs without to show the edit links in a different way.
kiamlaluno
Of course, if I remove the tabs, I'm planning to provide access to the content from back-end. I'm not letting the user to type by himself the path.
Patrick
A: 

On the module side, you could do something that decouples the Edit's menu entry from the local tasks for the node:

function custom_menu_alter(&$items) {
  $items['node/%node/edit']['type'] = MENU_CALLBACK;
}

The edit path is still there, but now it is not associated with the View tab. This includes the edit page itself--no View tab there.

Grayside
+1  A: 

This really is a presentational thing, not a functionality thing, so it should be done at the theme level.

The problem with overriding theme_menu_local_tasks() is that you override/take a hatchet to the entire local task display, when you really just want to get in there with a scalpel to remove two specific local tasks. So, you need to get a little more specific.

theme_menu_local_tasks() gets the current page's local tasks and passes them to menu_local_tasks(). Here, two theme functions are used:

  1. theme_menu_item_link(), which gets the link markup for the task
  2. theme_menu_local_task(), which gets the <li> element for the task.

So, you can get rid of the View and Edit local tasks in a really robust way by overriding theme_menu_item_link() and theme_menu_local_task() to include your check for them:

function mytheme_menu_item_link($link) {
  // Local tasks for view and edit nodes shouldn't be displayed.
  if ($link['type'] & MENU_LOCAL_TASK && ($link['path'] === 'node/%/edit' || $link['path'] === 'node/%/view')) {
    return '';
  }
  else {
    if (empty($link['localized_options'])) {
      $link['localized_options'] = array();
    }

    return l($link['title'], $link['href'], $link['localized_options']);
  }
}

function mytheme_menu_local_task($link, $active = FALSE) {
  // Don't return a <li> element if $link is empty
  if ($link === '') {
    return '';
  }
  else {
    return '<li '. ($active ? 'class="active" ' : '') .'>'. $link ."</li>\n";  
  }
}

This way, you're relying on the menu router path, not modifying the menu router item, and achieving the result you want with minimal changes to core functionality or theming.

Mark Trapp

related questions