How to hide Edit | View tabs?

2019-03-09 09:21发布

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

10条回答
Bombasti
2楼-- · 2019-03-09 09:53

For all the people stumbling upon this question while looking for a D7 solution: As stated on https://drupal.stackexchange.com/a/77964/15055 it's hook_menu_local_tasks_alter()

/**
 * Implements hook_menu_local_tasks_alter() to unset unwanted tabs
 */
function MYMODULE_menu_local_tasks_alter(&$data) {
  foreach ($data['tabs'][0]['output'] as $key => $value) {
    if ($value['#link']['path'] == 'node/%/view') {
      unset($data['tabs'][0]['output'][$key]);
    }
  }
}
查看更多
爷的心禁止访问
3楼-- · 2019-03-09 09:55

Thanks for the last answer. But be aware of this detail: if you try it as-is it cannot work: literals should be just rounded with " or ', not both of them altogether. So it should be:

/**
 * Implements hook_menu_local_tasks_alter() to unset unwanted tabs
 */
function MYMODULE_menu_local_tasks_alter(&$data) {
  foreach ($data['tabs'][0]['output'] as $key => $value) {
    if ($value['#link']['path'] == "node/%/view") {
      unset($data['tabs'][0]['output'][$key]);
    }
  }
}

Once taken care of it, it works :)

查看更多
一纸荒年 Trace。
4楼-- · 2019-03-09 09:56

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 :)

查看更多
我想做一个坏孩纸
5楼-- · 2019-03-09 09:56

This is not the answer to the question of what the author asked. But somehow it might be useful for others user who facing the similar problem with me. Please let me know if this is not suitable to put in here.

I get the answer from @grayside and modified a bit to hide the view | edit tab from node based on the content type I want.

    function MYMODULE_menu_alter(&$items) { 
      $items['node/%node/view']['access callback'] = 'MYMODULE_disable_node_view';
      $items['node/%node/view']['access arguments'] = array(1); 
    } 

    function MYMODULE_disable_node_view($node){
      if($node->type == 'product'){
        return false;
      }
    }

product is the machine name of my content type, I don't want anywant to access it including root user.

查看更多
登录 后发表回答