0

I'm trying to create tab in node display that links to node delete form. I used hook_menu_local_tasks_alter in template.php

function mytheme_menu_local_tasks_alter(&$data, $router_item, $root_path) {
// Add a tab linking to node/add to all pages.
$data ['tabs'][0]['output'][] = array(
'#theme' => 'menu_local_task',
'#link' => array(
    'title' => t('Delete'),
    'tab_parent' => 'node/%',
    'tab_root' => 'node/%',
    'tab_root_href' => 'node/'.arg(1),
    'tab_parent_href' => 'node/'.arg(1),
    'href' => 'node/'.arg(1).'/delete',
    'access callback' => 'node_access',
    'access arguments' => array('delete', 1),
    'localized_options' => array(
    'attributes' => array(
     'title' => t('Delete'),
    ),
  ),
),

);

}

Tab is created but it is displayed for every user and on every page where tabs are enabled. How can I configure access arguments to display tab only on node display page and only for user with permissions [Content type]: delete own content?

0

This will be done by hook_menu, See the example below for creating tabs (MENU_LOCAL_TASK). This is how tabs will be created.

    // For the default local task, we need very little configuration, as the
  // callback and other conditions are handled by the parent callback.
  $items['examples/menu_example/tabs/default'] = array(
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'title' => 'Default primary tab',
    'weight' => 1,
  );
  // Now add the rest of the tab entries.
  foreach (array(
    t('second') => 2,
    t('third') => 3,
    t('fourth') => 4,
  ) as $tabname => $weight) {
    $items["examples/menu_example/tabs/$tabname"] = array(
      'type' => MENU_LOCAL_TASK,
      'title' => $tabname,
      'page callback' => '_menu_example_menu_page',
      'page arguments' => array(t('This is the tab "@tabname" in the "basic tabs" example', array('@tabname' => $tabname))),
      'access callback' => TRUE,

      // The weight property overrides the default alphabetic ordering of menu
      // entries, allowing us to get our tabs in the order we want.
      'weight' => $weight,
    );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.