Hello, I'm trying to add local tasks to a views display page. However, everything I am trying is not working. My most recent tries have involved using the following code:

function MYMODULE_menu($may_cache) {

$items = array();
if ($may_cache) {
// ...
} else {
$items[] = array(
'path' => 'news/manage',
'title' => t('Manage News'),
'callback' => 'MYMODULE_redirect',
'type' => MENU_LOCAL_TASK,
);
}
return $items;
}
function MYMODULE_redirect() {
// This will redirect to a real page that already exists.
}

I've been looking through examples for hours on adding local tasks to nodes, but I just can't seem to get it to work for a view. The exact task I'm trying to do is add a "Manage News" tab onto a view that lists news articles. The Manage News items link already exists elsewhere, therefore I'm not really needing to create a new page, just redirect to the one that already exists.

Any help would be appreciated. Thanks!

Comments

Carolyn’s picture

A few things. One, you need to set a menu path for news, and then create at least two local tasks. You could set the default tab in the views UI under menu, or you could embed the view in the code. The code for local tasks would look something like this:

<?php
  $items['news'] = array (
    'title' => 'News',
    'page callback' => 'yourfunction_callnewsview',
    'access callback' => 'user_access',
    'access arguments' => array('access all views'),
    'type' => MENU_NORMAL_ITEM,
	'menu_name' => 'primary-links',
    );

  $items['news/view'] = array (
    'title' => 'News',
    'page callback' => 'yourfunction_callnewsview',
    'access callback' => 'user_access',
    'access arguments' => array('access all views'),
    'type' => MENU_LOCAL_TASK,
    );

  $items['news/manage'] = array (
    'title' => 'Manage News 2',
    'page callback' => 'yourfunction_redirect',
    'access callback' => 'user_access',
    'access arguments' => array('access all views'),
    'type' => MENU_LOCAL_TASK,
    );
?>