I have created a View with multiple page displays. I have specified one as the "default tab" and the other two as "tab" and they all display correctly together on a page similar to this:
I would like to be able to insert another tab onto this page with module generated code (not from a view). Is this possible?
Using the menu hook you can define another tab for the page similar to below:
function MODULENAME_menu() {
$items = array();
$items['PATH_TO_VIEW_DEFAULT_TAB/YOUR_NEW_TAB'] = array(
'title' => 'TAB TITLE',
'page callback' => 'FUNCTION NAME',
'page arguments' => array('ACCESS ARGUMENT'),
'access callback' => 'user_access',
'access arguments' => array('ACCESS ARGUMENT'),
'type' => MENU_LOCAL_TASK,
'weight' => 10
);
return $items;
}
Related
I'm building a fairly involved module for my company with a number of different configuration pages. I'd like there to be a menu item in the admin bar across the top that has all the sub menu items as well. I know how to add a single item to that menu through the UI, but there will be enough pages I'd just prefer to do it through the module itself. So, how can I add an item with a submenu to sit up alongside 'Dashboard', 'Content', 'Structure', etc. in the admin menu in my module file. I assumed it had to be in hook_menu(), but I can't figure it out.
This could be achieved by adding a 'page callback' of system_admin_menu_block_page to your hook_menu implementation:
So, lets say you want to create a structure like the following :
Custom main menu (will appear on the toolbar, besides other items like Structure, Modules, etc)
Sub menu item 1
Sub menu item 2
The hook implementation would be something like :
function MODULE_menu() {
$items['admin/main'] = array(
'title' => 'Custom main menu',
'description' => 'Main menu item which should appear on the toolbar',
'position' => 'left',
'weight' => -100, // Less weight so that it will appear to the extreme left, before dashboard.
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('administer site configuration'),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
);
$items['admin/main/sub-menu-1'] = array(
'title' => 'Sub menu item 1',
'description' => 'Child of the menu appearing in toolbar.',
'page callback' => 'drupal_get_form',
'page arguments' => array('custom_form'),
'access arguments' => array('custom permission'),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/main/sub-menu-2'] = array(
'title' => 'Sub menu item 2',
'description' => 'Child of the menu appearing in toolbar.',
'page callback' => 'custom_page_callback',
'access arguments' => array('custom permission'),
'type' => MENU_NORMAL_ITEM,
);
}
P.S - After enabling the module, or adding this code to the hook_menu implementation, you'll have to flush the cache so that Drupal picks up the new menu structure.
I'm wondering which is the best way to display a form on a page (for example : a register form for vip users ... and not in a block but as the main content).
The user.module way in user_menu (*hook_menu*) :
$items['vip/register'] = array(
'title' => 'Create new vip account',
'page callback' => 'drupal_get_form',
'page arguments' => array('vip_register_form'),
'access callback' => 'user_register_access',
'type' => MENU_LOCAL_TASK,
);
Or by creating a theme via use_theme (*hook_theme*) (fictive) :
$items['vip/register'] = array(
'title' => 'Create new vip account',
'page callback' => 'theme',
'page arguments' => array('vip_register'),
'access callback' => 'user_register_access',
'type' => MENU_LOCAL_TASK,
);
function user_theme() {
return array(
'vip_register' => array(
)
);
}
function theme_vip_register(){
return drupal_get_form('vip_register_form');
}
I'm wondering about this for theming purpose, because a designer will do the graphic integration afterwards.
Thank you for advices.
This is not an actual answer but I'm not quite sure what is your question at first place.
Drupal customs #1: Never hack core!
As its name, theme functions are just to theme something. So you need the form built first.
$items['vip/register'] = array(
'title' => 'Create new vip account',
'page callback' => 'drupal_get_form',
'page arguments' => array('vip_register_form'),
'access callback' => 'user_register_access',
'type' => MENU_LOCAL_TASK,
);
When a user accesses example.com/vip/register page, drupal_get_form function will be called with argument vip_register_form.
So now you need to define a function to return this (vip user registration) form.
function vip_register_form($form, &$form_state){
..your FAPI stuff here.
return $form;
}
Now user who open the vip register page will see this form instead of the regular form. even password and username fields will not be available unless you add them. If you want to alter the existing form, just copy the menu hook to a new path:
$user_menu_routers = user_menu();
$items['vip/register'] = $user_menu_routers['user/register'];
Now you can alter your the form at vip/register page (which is same as normal user register page) using a form_alter hook. You can theme the form manually without affecting existing one as well.
I'm new for Drupal , so I want to create a simple module that custom user profile, specically I want insert some tabs for user profile (the traditional user profile have 2 tabs "View tab" and "Edit Tab") so now I want add more 3 tabs.
Show History
Share profile
Shortcuts
but it only apply for user authenticated not admin profile (when admin show his profile ,the profile is traditional profile).
So it my code (my module's name is :tung_tab) and here is code of tung_tab.module:
function tung_tab_menu()
{
$items = array();
global $user;
//if (!user_access('administer'))
if($user->uid!=1)
{
$items['user/%/rvhistory'] = array(
'title' => 'Review History ',
'description' => 'Review History',
//'page callback' => 'drupal_get_form',
//'page arguments' => array('tung_tab_confirm_reviewh', 1),
'access callback' => 'user_view_access',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
);
$items['user/%/sharehistory'] = array(
'title' => 'Share History',
'description' => 'Share History',
//'page callback' => 'drupal_get_form',
//'page arguments' => array('tung_tab_confirm_shareh', 1),
'access callback' => 'user_view_access',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
);
$items['user/%/sc'] = array(
'title' => 'Shortcut',
'description' => 'Shortcut',
//'page callback' => 'getDescription',
//'page arguments' => array('tung_tab_confirm_shareh', 1),
'access callback' => 'user_view_access',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
);
}
return $items;
}
It work properlly for admin tab, but when I log out and then login with other user
but not thing is changed, so if I comment the line //if($user->uid), everthing is ok
so when I add more code in this line
'title' => 'Review History '.$user->uid,
When I'm admin It show that Review History 1
When I loged in with another account , everything is the same , Review History 1
I can't understand why? I think my code get some mistake
I put my module in "mysite/sites/default/modules/"
You shouldn't define the menu items inside the if condition. You should control the access to the menu callbacks using access callback and access arguments instead.
WRONG:
function tung_tab_menu()
{
$items = array();
global $user;
if($user->uid!=1)
{
// defined menu items
}
return $items;
}
CORRECT:
function tung_tab_menu()
{
$items = array();
global $user;
// define the menu items here...
return $items;
}
Try to fix that then see if you still get the same results.
I have a content type "activities", which has three fields:
1- Programs
2- Implementation
3- Project Stories
How can I display each field in the node in a separate tab?
Thanks!
I have found an easier way to do it using the field_group module. From "Manage Display" the fields can be added to horizontal tabs fieldgroups and then the horizontal tabs fieldgroups can be added to a horizontal tabs group. See the image for further information.
In my opinion there are two ways you can achieve this.
1) Using the hook_menu() to create the tabs for your content type.
Here you will have to write your own module and the code will look something like this
/**
* Implements hook_menu().
*/
function pages_menu() {
$items['pages'] = array(
'title' => 'Menu system examples',
'description' => 'Menu system example that returns a string.',
'page callback' => 'pages_string',
'access callback' => TRUE,
);
$items['pages/default'] = array(
'title' => 'String',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['pages/render-array'] = array(
'title' => 'Render array',
'description' => 'Menu system example using a render array.',
'page callback' => 'pages_render_array',
'access arguments' => array('access content'),
'weight' => 2,
'type' => MENU_LOCAL_TASK,
);
$items['pages/render-array/tab1'] = array(
'type' => MENU_DEFAULT_LOCAL_TASK,
'title' => 'Tab 1',
);
$items['pages/render-array/tab2'] = array(
'title' => 'Tab 2',
'description' => 'Demonstrating secondary tabs.',
'page callback' => 'pages_render_array',
'access callback' => TRUE,
'type' => MENU_LOCAL_TASK,
);
return $items;
}
You then use the call back function to do your think in each of the tabs
2) Using Css and jquery to style the content in a way that it looks like a tab.
here is a great working demo for you. http://www.99points.info/2010/08/create-sexy-animated-tabs-using-jquery-and-css/
Cheers,
Vishal
A quick search on Drupal moduels gets this:
D6 - http://drupalmodules.com/module/cck-fieldgroup-tabs
D7 - http://drupal.org/project/field_group
One other module to consider, if anyone else comes looking for an answer: http://drupal.org/project/node_subpages
[[shameless plug]]
I want to add a tab to Drupal node like in the following picture:
The picture has 3 tabs, Views, CVS Instructions, Revisions. I want to add another tab "Translation". What module should I use?
The picture was taken from http://drupal.org/project/panels_tabs
Thank you.
I would create a simple small module that has a hook_menu implementing the tab.
See the example here:
http://drupal.org/node/678984
As for the rest of your implementation, I don't know what you are trying to achieve, but this will add tabs.
Not sure if this is relevant but if you are actually looking to translate node content then have you investigated the Internationalization module?
The translation tab is handled by the module "Content translation" that depends from "Locale"; once you enabled the module, you need also to set which content types can be translated, and other settings that change the way a node of that content type is translated.
Not quite what was asked, but here is code for hook_menu in a custom module that sets up an administration menu option with 2 tabs.
/***************************************************************
* hook menu
*/
function acme_viewer_setup_menu(){
$items = array();
// administration setting - call from URL
$items['admin/settings/acme_viewer_setup'] = array(
'title' => 'Acme Misc Setup - viewer and Blog', // title in Admin menu
'description' => 'Acme Misc Setup: acme viewer & Blog',
'page callback' => 'drupal_get_form', // Retrieves form 'acme_viewer_setup_admin'
'page arguments' => array('acme_viewer_setup_admin'),
'access arguments' => array('access administration pages'), // only users who can access admin pages
'type' => MENU_NORMAL_ITEM,
);
// tab 1 - viewer
$items['admin/settings/acme_viewer_setup/viewer'] = array(
'title' => 'Configure viewer', // title in tab
'page callback' => 'drupal_get_form',
'page arguments' => array('acme_viewer_setup_admin'),
'access callback' => 'user_access',
'access arguments' => array('access administration pages'),
'type' => MENU_LOCAL_TASK,
);
// tab 2 - blog
$items['admin/settings/acme_viewer_setup/blog'] = array(
'title' => 'Configure Blog', // title in tab
'page callback' => 'drupal_get_form',
'page arguments' => array('blog_setup_admin'),
'access callback' => 'user_access',
'access arguments' => array('access administration pages'),
'type' => MENU_LOCAL_TASK,
);
return $items;
}