문제

I am using the following code to include a custom tab for my node types:

function mymodule_menu(){
    $items['node/%node/register']   =   array(
        'page arguments' => array(1),
        'access arguments'  =>  array('access content'),
        'type'  =>  MENU_LOCAL_TASK,
        'title' =>  'Register',
    );
    return $items;
}

This has the effect of including a register tab for every node type. However, I need to include that tab for only page types and exclude it on all other type like article types etc.

Can anyone please offer some direction?

도움이 되었습니까?

해결책

The easiest way would be to provide your own access callback that checks the node type, e.g.

function mymodule_menu(){
  $items['node/%node/register'] = array(
    'page arguments' => array(1),
    'access callback' => 'mymodule_node_register_tab_access',
    'access arguments' => array(1),
    'type'  =>  MENU_LOCAL_TASK,
    'title' =>  'Register',
  );
  return $items;
}

function mymodule_node_register_tab_access($node) {
  $valid_types = array('page');
  return in_array($node->type, $valid_types);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top