I am trying out the new view and edit tabs on the view and generally it seems to work OK, but I can't figure out how I could add a custom tab to the end of the tabs created by Views. Doing it the usual way in hook_menu() works fine at first and adds the tab at the right of the Views tabs, but as soon as I select my custom tab I get the Views tabs showing up as second level tabs below my tab, and their paths are broken.

As an example, I added this to hook_menu to create a setup tab:

     $items[] = array(
        'path'     => $view->url .'/setup',
        'title'    => t('Setup'),
        'description' => t('Calendar setup.'),
        'access'   => user_access('administer content'),
        'callback' => 'drupal_get_form',
        'callback arguments' => array('calendar_setup_form', $view),
        'type' => MENU_LOCAL_TASK,
        'weight' => 5,
      );

It looks just as it should in the initial display of my view and as long as I use any of the Views tabs. However, as soon as I click on my custom tab, the 'View' tab shows up as a second level menu tab below my 'Setup' tab, and the 'View' tab has a path of 'calendar/setup', instead of the right path of 'calendar'.

Maybe there's some Views function I should use instead of hook_menu(), and I see you have a few menu functions in there, but I can't quite figure out which one I should use to get the right results.

Or maybe I should just not be screwing around with your tabs :-)

Thanks, BTW, I think this is a really great feature.

CommentFileSizeAuthor
#2 views.module_29.patch2.23 KBkarens

Comments

merlinofchaos’s picture

I had initially tried to make it so that views_ui_add_admin_tabs was actually a hook, and any module could add the tabs.

Then I realized that I couldn't tell if I was already looking at a tab or not, and the only solution I could think of was to look at the end of the URL and see if it is 'edit', 'clone', 'export' or 'view' and if it is, hey, we're looking at a tab.

Soooo if you add your own tab, you get hit by that code. I welcome suggestions for ways to deal with this cleanly, as I don't like the solution I have.

karens’s picture

Status: Active » Needs review
StatusFileSize
new2.23 KB

What about something like this. I created a hook_views_tabs(), where modules can identify their tabs. I tested this in my own application with two custom tabs added by two different modules and it seems to work fine.

merlinofchaos’s picture

Status: Needs review » Fixed

Looks like an acceptable solution, and better whan what I've got. Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)
gemini’s picture

I actually got around without using the patch.
I looked up the views_ui_add_menu_items() and copied first 2 items from it into my custom function, so it now looks like this and works:

custom_menu($may_cache, $args = array()) {
  $items = array();
  if (module_exists('views_ui')) {
	$items[] = array('path' => business-listings,
        'title' => t('View'),
        'callback' => 'views_view_page',
        'callback arguments' => array_merge(array($view->name), $args),
        'access' => user_access('create business_listing content'),
        'type' => MENU_CALLBACK);
    
    $items[] = array('path' => "business-listings/view",
      'title' => t('View'),
      'callback' => 'views_page',
      'callback arguments' => array_merge(array($view->name), $args),
      'access' => user_access('create business_listing content'),
      'weight' => -10,
      'type' => MENU_DEFAULT_LOCAL_TASK);
	 
	  $items[] = array(
	    'path' => 'business-listings/submit',
        'title' => t('Submit New Listing'),
        'callback' => 'custom_submit',
        'callback arguments' => array('business_listing'),
        'access' => user_access('create business_listing content'),
        'type' => MENU_LOCAL_TASK,
      );
  }
  return $items;
}

Basically it adds 2 tabs: View and Submit New Listing in my case. Works without any patches.

traceelements’s picture

Version: 5.x-1.x-dev » 6.x-2.6
Status: Closed (fixed) » Active

This is exactly what I'm trying to do. Please excuse my ignorance, but where do I go to copy it into a "custom function"? I see this earlier thread was for 5.x. Will this still apply to 6.x?

merlinofchaos’s picture

Version: 6.x-2.6 » 5.x-1.x-dev
Status: Active » Closed (fixed)

Nothing in this issue is applicable to Views for D6. Resetting status.

anuradha parashar’s picture

Title: Add custom tab to new view/edit tabs » How to manage quiz question information in two tabs(quiz module)
Version: 5.x-1.x-dev » 6.x-2.0
Component: Code » Views Data
Assigned: Unassigned » anuradha parashar
Priority: Normal » Critical
Status: Closed (fixed) » Needs work

Hi,
i m working on assessment authoring soluction.In it i want to do some changes in quiz module like when we create new question of any question type that time whole details are shown in same page but now i want to show these details in two sprate tabs...like in 1st tab i can only create a question and 2nd tab i can do the configration of that perticular question.what i do for the same.
plese help me as soon as possible

Thanks in advance :-)

esmerel’s picture

Version: 6.x-2.0 » 5.x-1.x-dev
Component: Views Data » Code
Assigned: anuradha parashar » Unassigned
Priority: Critical » Minor
Status: Needs work » Closed (fixed)

1) Please do not reopen old issues, especially ones that have been closed for 2 years. Open a new issue.
2) Do not change all of the data associated with an issue - that messes things up for other people, and it shows that your issue is completely unrelated to the previous issue, indicating that you need to open a new issue.
3) Support requests are never critical.
4) Needs work is for patches only.