How to display node fields in tabs? - drupal

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]]

Related

Drupal add menu link to user menu

In Drupal 7 module development, supposedly by using the hook_menu function, how can I add menu link to the user menu?
Here.
I found easily it in the administration but I can't find how to do it programmatically, I haven't found any menu type that would fit this situation.
Thanks.
You could specify the menu_name in the data returned by your hook_menu():
function MYMODULE_menu() {
$items['example'] = array(
'title' => 'Example Page',
'page callback' => 'example_page',
'menu_name' => 'user-menu', // << Menu name
'weight' => 12, // << position
'access arguments' => array(
'access content',
),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
By default, it is added in the Navigation menu.

Drupal 7: Add Item to Admin Toolbar/Menu Programmatically

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.

Creating a menu item that links to its parent

I've been searching low an high to do this. I want to create a normal menu item programatically that links to its parent. Similar to the concept of default menu task, but just a normal menu item. Has anyone ever done this?
I want something that I can do with one of the drupal hooks.
You just need to create a new menu-item, that has the same path as its parent.
$items['parent'] = array(
'title' => 'I am parent',
'page callback' => 'drupal_get_form',
'page arguments' => 'get_parent',
'access arguments' => array('access parent'),
'type' => MENU_NORMAL_ITEM,
);
$items['parent/child'] = array(
'title' => 'I am child link of parent',
'page callback' => 'drupal_get_form',
'page arguments' => 'get_children_for_thisparent',
'access arguments' => array('access children of parent'),
'type' => MENU_NORMAL_ITEM,
);
This should do the trick :)
Suppose you want to place it under Main menu,
$item['form_example'] = array(
'title' => 'Example menu',
'description' => 'This is an example menu item',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'custom_function',
'menu_name' => 'main-menu',
);
return $item;
You will then get the menu item under Main menu (clearing cache). The trick is adding a key 'menu_name'.
To get the menu_name please open the menu administration page, and click on 'edit menu' on any root menu. URL will be like 'SITE_URL/admin/structure/menu/manage/main-menu/edit'. Look at the url segment just before the last(here main-menu).
For the second case you might want to place it under Home of main menu. The code is.
$item['form_example'] = array(
'title' => 'Example menu',
'description' => 'This is an example menu item',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'custom_function',
'menu_name' => 'main-menu',
'plid' => 218,
);
return $item;
Here, I have added a key plid to associative array, it is the mlid of the menu item('Home' here) for which it will be a child. For this case it will be child of Home menu.
To get the mlid you have to do the same as described above, goto menu administration page and click list links and then click edit on the menu item, e.g. SITE_URL/admin/structure/menu/item/218/edit, thus you can get the mlid and thus its done.
Note. If you change this menu hierarchy or other settings from back-end, you will always have reset option to reset it, and after resetting it will behave like described in the code.

Can I combine Views page tabs with module generated tabs?

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;
}

How to split the code of a module into separated files

I am very curious to know how a Drupal module can be dis-integrated into multiple include files. A number of hook support to link include components, like hook_menu, hook_theme etc.
Once I planned to simplify one of my complex module that have reached to 2.3K of lines with half of its feature set. I have to roll back all those steps due to lack of knowledge about the scope of inclusion.
Help me in this regard if there is some detailed information.
What Nikit said is correct.
I will add there are some hooks that are allowed to define which files need to be loaded. Examples of such hooks are hook_theme(), and hook_menu().
A module should never unconditionally load a file it needs calling module_load_include() from outside a function.
function book_menu() {
$items['admin/content/book'] = array(
'title' => 'Books',
'description' => "Manage your site's book outlines.",
'page callback' => 'book_admin_overview',
'access arguments' => array('administer book outlines'),
'file' => 'book.admin.inc',
);
$items['admin/content/book/list'] = array(
'title' => 'List',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/content/book/settings'] = array(
'title' => 'Settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('book_admin_settings'),
'access arguments' => array('administer site configuration'),
'type' => MENU_LOCAL_TASK,
'weight' => 8,
'file' => 'book.admin.inc',
);
// …
}
function user_theme() {
return array(
'user_picture' => array(
'arguments' => array('account' => NULL),
'template' => 'user-picture',
),
'user_profile' => array(
'arguments' => array('account' => NULL),
'template' => 'user-profile',
'file' => 'user.pages.inc',
),
// …
'user_admin_perm' => array(
'arguments' => array('form' => NULL),
'file' => 'user.admin.inc',
),
// …
);
}
Using more files, is just a matter of grouping similar things together in the same file, to keep it more managed. Typical files used is
.admin.inc for all administration stuff, menu callbacks, forms etc.
.pages.inc for frontend menu callbacks.
.theme.inc for theme functions, preprocess hooks etc.
.forms.inc for non admin forms and their handlers.
This is more a coding style that anything else. So this is just to help yourself maintain the code you have written.
It's simple, just review other big modules (like cck, views, etc). Main hooks should be in module, others should be in different files - themers, admin pages, other pages, service functions and so on...

Resources