The Quick Tabs module allows you to create blocks of tabbed content. You can create a block on your site containing up to six tabs with corresponding content. Clicking on the tabs makes the corresponding content display instantly (it uses jQuery). The content for each tabbed section can be either a view or an existing block. It is an ideal way to do something like the Most Popular / Most Emailed stories tabs you see on many news websites.

Once created, the Quick Tabs blocks show up in your block listing, ready to be configured and enabled like other blocks.

Multiple Quick Tabs blocks can be placed on a single page.

Visit the Quick Tabs configuration page to choose a style for your Quick Tabs blocks.

Click on the "New QT block" tab below to get started.

', array('@configuration' => url('admin/settings/quicktabs'))); case 'admin/build/quicktabs/add': return '

'. t('Here you can create a new Quick Tabs block. Once you have created this block you will be taken to the blocks page to configure and enable it.', array('@overview' => url('admin/build/block'))) .'

'; } } /** * Implementation of hook_menu(). */ function quicktabs_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array( 'path' => 'admin/build/quicktabs', 'title' => t('Quick Tabs'), 'description' => t('Create blocks of tabbed content - content for each tab can be a view or a block'), 'callback' => 'quicktabs_list', 'access' => user_access('administer quicktabs blocks'), ); $items[] = array('path' => 'admin/build/quicktabs/list', 'title' => t('List'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); $items[] = array( 'path' => 'admin/build/quicktabs/add', 'title' => t('New QT block'), 'access' => user_access('create quicktabs block'), 'callback' => 'quicktabs_new', 'type' => MENU_LOCAL_TASK); $items[] = array('path' => 'admin/build/quicktabs/delete', 'title' => t('Delete QT block'), 'access' => user_access('administer blocks'), 'callback' => 'drupal_get_form', 'callback arguments' => array('quicktabs_block_delete'), 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/build/quicktabs/edit', 'title' => t('Edit QT block'), 'access' => user_access('administer blocks'), 'callback' => 'quicktabs_block_edit', 'type' => MENU_CALLBACK); $items[] = array( 'path' => 'admin/settings/quicktabs', 'title' => t('Quick Tabs'), 'description' => t('Select a style for your Quick Tabs blocks'), 'callback' => 'drupal_get_form', 'callback arguments' => array('quicktabs_settings'), 'type' => MENU_NORMAL_ITEM, 'access' => user_access('administer site configuration'), ); $items[] = array( 'path' => 'quicktabs/preview', 'callback' => 'quicktabs_preview_page', 'type' => MENU_CALLBACK, 'access' => user_access('administer site configuration'), ); } return $items; } /** * Implementation of hook_perm(). */ function quicktabs_perm() { return array('create quicktabs block', 'administer quicktabs blocks'); } function quicktabs_list() { $result = db_query('SELECT * FROM {quicktabs}'); $header = array(t('Quick Tabs Block Name'), t('Delete')); $rows = array(); while ($row = db_fetch_object($result)) { $tablerow = array( array('data' => $row->title .' ('. l('edit', 'admin/build/quicktabs/edit/'. $row->qtid) .')'), array('data' => l(t('Delete'), 'admin/build/quicktabs/delete/'. $row->qtid)), ); $rows[] = $tablerow; } $output = theme('table', $header, $rows, array('id' => 'quicktabs')); return $output; } function quicktabs_new() { drupal_add_js(drupal_get_path('module', 'quicktabs') .'/js/quicktabs_form.js'); $output = ''; if (module_exists('views')) { $views = quicktabs_get_views(); } else { $views = NULL; } $blocks = quicktabs_get_blocks(); $output .= drupal_get_form('quicktabs_form', $views, $blocks); return $output; } function quicktabs_get_views() { views_load_cache(); $result = db_query("SELECT v.name, v.description, f.field FROM {view_view} v LEFT JOIN {view_exposed_filter} f ON v.vid=f.vid"); $views = array(); while ($view = db_fetch_object($result)) { if (!($view->field)) { $views[$view->name] = $view->name .': '. $view->description; } } $default_views = _views_get_default_views(); $views_status = variable_get('views_defaults', array()); foreach ($default_views as $view) { if (!$views[$view->name] && ($views_status[$view->name] == 'enabled' || (!$views_status[$view->name] && !$view->disabled)) && empty($view->exposed_filter)) { $views[$view->name] = check_plain($view->name .': '. $view->description); } } return $views; } function quicktabs_get_blocks() { $blocks = _block_rehash(); $blocksarray = array(); foreach ($blocks as $i => $block) { if ($block['module'] != 'quicktabs') { $key = $block['module'] .'_delta_'. $block['delta']; $blocksarray[$key] = $block['info']; } } return $blocksarray; } function quicktabs_form($views, $blocks, $form_values=NULL) { $form = array(); $form['#multistep'] = TRUE; $step = isset($form_values) ? (int) $form_values['step'] : 1; $form['step'] = array( '#type' => 'hidden', '#value' => $step + 1 ); $form['indicator'] = array( '#type' => 'fieldset', '#title' => ($step == 1 ? t('QT: Basic Information') : t('QT: Tab contents')) ); switch ($step) { case 1: $form['formtype'] = array( '#type' => 'hidden', '#value' => 'new' ); $form['indicator']['title'] = array( '#title' => t('Block Title'), '#type' => 'textfield', '#description' => t('The title of the whole block'), '#weight' => 0 ); $form['indicator']['num_tabs_options'] = array( '#type' => 'value', '#value' => array( '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6 ) ); $form['indicator']['num_tabs'] = array( '#title' => t('Number of tabs'), '#type' => 'select', '#options' => $form['indicator']['num_tabs_options']['#value'], '#weight' => 1 ); break; case 2: $blocktitle = $form_values['title']; $form['indicator']['title'] = array( '#type' => 'hidden', '#value' => $blocktitle ); $form['indicator']['showtitle'] = array( '#type' => 'markup', '#value' => $blocktitle, ); $i=1; $tabs = $form_values['num_tabs']; $formtype = $form_values['formtype']; $form['formtype'] = array( '#type' => 'hidden', '#value' => $formtype ); if ($formtype == 'edit') { $tabcontent = $form_values['tabs']; $form['qtid'] = array( '#type' => 'hidden', '#value' => $form_values['qtid'] ); } while ($i <= $tabs) { $form['indicator']['tab_'. $i] = array( '#type' => 'fieldset', '#title' => t('Tab '. $i), '#weight' => $i ); $form['indicator']['tab_'. $i]['title_'. $i] = array( '#type' => 'textfield', '#title' => t('Tab title'), '#default_value' => $tabcontent[$i-1]['title'] ? $tabcontent[$i-1]['title'] : NULL, '#description' => t('The title to appear on the tab itself') ); if (module_exists('views')) { $form['indicator']['tab_'. $i]['type_options'] = array( '#type' => 'value', '#value' => array( 'block' => 'block', 'view' => 'view', ) ); $form['indicator']['tab_'. $i]['type_'. $i] = array( '#type' => 'radios', '#options' => $form['indicator']['tab_'. $i]['type_options']['#value'], '#title' => t('Tab Content'), '#default_value' => $tabcontent[$i-1]['type'] ? $tabcontent[$i-1]['type'] : 'block', '#description' => t('Will this tab contain a view or a block?') ); $form['indicator']['tab_'. $i]['vid_'. $i] = array( '#type' => 'select', '#options' => $views, '#default_value' => $tabcontent[$i-1]['type']=='view' ? $tabcontent[$i-1]['bvid'] : NULL, '#title' => t('Select a view') ); $form['indicator']['tab_'. $i]['args_'. $i] = array( '#type' => 'textfield', '#title' => 'arguments', '#required' => false, '#default_value' => $tabcontent[$i-1]['type']=='view' ? $tabcontent[$i-1]['args'] : NULL, '#description' => t('Provide a comma separated list of arguments to pass to the view.'), ); $form['indicator']['tab_'. $i]['limit_'. $i] = array( '#type' => 'textfield', '#title' => t('Limit'), '#default_value' => $tabcontent[$i-1]['type']=='view' ? $tabcontent[$i-1]['limit'] : NULL, '#description' => t('Limit the number of results') ); } else { $form['indicator']['tab_'. $i]['type_'. $i] = array( '#type' => 'hidden', '#value' => 'block' ); } $form['indicator']['tab_'. $i]['bid_'. $i] = array( '#type' => 'select', '#options' => $blocks, '#default_value' => $tabcontent[$i-1]['type']=='block' ? $tabcontent[$i-1]['bvid'] : NULL, '#title' => t('Select a block') ); $i++; } break; } if ($step < 2) { $form['submit'] = array( '#type' => 'submit', '#value' => t('Next') ); $form['#redirect'] = FALSE; } else { $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), ); } return $form; } function quicktabs_form_validate($form_id, $form_values) { if ($form_values['step'] < 3) { if (empty($form_values['title'])) { form_set_error('title', t('You must give your Quick Tabs block a title.')); } return; } else { $done = FALSE; $j=1; while (!$done) { if (!isset($form_values['title_'. $j])) { $done = TRUE; } else { if (empty($form_values['title_'. $j])) { form_set_error('title_'. $j, t('You must give each tab a title.')); } if ($form_values['type_'. $j] == 'view' && empty($form_values['limit_'. $j])) { form_set_error('limit_'. $j, t('You must enter a limit for each view.')); } } $j++; } } } function quicktabs_form_submit($form_id, $form_values) { if ($form_values['step'] < 3) { return; } $formvalues_tabs = array(); $done = FALSE; $j=1; while (!$done) { if (!isset($form_values['title_'. $j])) { $done = TRUE; } else { $formvalues_tabs[] = array( 'title' => $form_values['title_'. $j], 'type' => $form_values['type_'. $j], 'bvid' => ($form_values['type_'. $j]=='block' ? $form_values['bid_'. $j] : $form_values['vid_'. $j]), 'args' => ($form_values['type_'. $j]=='block' ? '' : $form_values['args_'. $j]), 'limit' => ($form_values['type_'. $j]=='block' ? '0' : $form_values['limit_'. $j]) ); } $j++; } $fullcontent = array( 'blocktitle' => $form_values['title'], 'blockcontent' => $formvalues_tabs, ); if ($form_values['formtype'] == 'edit') { $qtid = $form_values['qtid']; quicktabs_updateblock($qtid, $fullcontent); $msg = t('Your Quick Tabs block has been updated.'); } else { quicktabs_createblock($fullcontent); $msg = t('Your Quick Tabs block has been created and can now be enabled.'); } drupal_set_message($msg); return 'admin/build/block'; } function quicktabs_createblock($fullcontent) { $qtid = db_next_id('quicktabs'); $title = $fullcontent['blocktitle']; $tabs = serialize($fullcontent['blockcontent']); db_query('INSERT INTO {quicktabs} (qtid, title, tabs) VALUES(%d, "%s", "%s")', $qtid, $title, $tabs); return; } function quicktabs_updateblock($qtid, $fullcontent) { $title = $fullcontent['blocktitle']; $tabs = serialize($fullcontent['blockcontent']); db_query('UPDATE {quicktabs} SET title="%s", tabs="%s" WHERE qtid=%d', $title, $tabs, $qtid); return; } /** * Implementation of hook_block */ function quicktabs_block($op = 'list', $delta = 0, $edit = array()) { switch ($op) { case 'list': $jqueryblocks = array(); $result = db_query('SELECT * FROM {quicktabs}'); while ($row = db_fetch_object($result)) { $jqueryblocks[$row->qtid] = $row->title; } foreach ($jqueryblocks as $key => $val) { $blocks[$key]['info'] = t($val); } return $blocks; break; case 'view': if ($jqueryblock = db_fetch_object(db_query('SELECT qtid, title, tabs FROM {quicktabs} WHERE qtid = %d', $delta))) { quicktabs_add_css(); drupal_add_js(drupal_get_path('module', 'quicktabs') .'/js/quicktabs.js'); $mainblock['subject'] = $jqueryblock->title; $tabs = unserialize($jqueryblock->tabs); $output = '
'; $output .= ''; $output .= '
'; foreach ($tabs as $j => $tab) { $output .= '
'; if ($tab['type'] == 'view') { if (module_exists('views')) { if ($tab['args']!='') { $args = explode(',', $tab['args']); } else { $args = array(); } $view = views_get_view($tab['bvid']); $output .= views_build_view('embed', $view, $args, false, $tab['limit']); } else { $output .= 'Views module not enabled, cannot display tab content'; } } else { $pos = strpos($tab['bvid'], '_delta_'); $blockmodule = substr($tab['bvid'], 0, $pos); $blockdelta = substr($tab['bvid'], $pos+7); $block = (object) module_invoke($blockmodule, 'block', 'view', $blockdelta); $block->module = $blockmodule; $block->delta = $blockdelta; $output .= $block->content ? theme('block', $block) : ''; } $output .= '
'; } $output .= '
'; $mainblock['content'] = $output; } return $mainblock; break; } } function quicktabs_block_get_name($qtid) { $result = db_result(db_query('SELECT title FROM {quicktabs} WHERE qtid=%d', $qtid)); return $result; } function quicktabs_block_delete($qtid) { $qt_name = quicktabs_block_get_name($qtid); $form['qtid'] = array('#type' => 'hidden', '#value' => $qtid); $form['qt_name'] = array('#type' => 'hidden', '#value' => $qt_name); return confirm_form($form, t('Are you sure you want to delete the Quick Tabs block %name?', array('%name' => $qt_name)), 'admin/build/quicktabs', '', t('Delete'), t('Cancel')); } function quicktabs_block_edit($qtid) { if ($qtblock = db_fetch_object(db_query('SELECT title, tabs FROM {quicktabs} WHERE qtid = %d', $qtid))) { $tabs = unserialize($qtblock->tabs); $form_values = array( 'step' => 2, 'qtid' => $qtid, 'title' => $qtblock->title, 'num_tabs' => count($tabs), 'tabs' => $tabs, 'formtype' => 'edit', ); drupal_add_js(drupal_get_path('module', 'quicktabs') .'/js/quicktabs_form.js'); $output = ''; if (module_exists('views')) { $views = quicktabs_get_views(); } else { $views = NULL; } $blocks = quicktabs_get_blocks(); $output .= drupal_get_form('quicktabs_form', $views, $blocks, $form_values); return $output; } else { drupal_goto('admin/build/quicktabs'); } } /** * Deletion of Quick Tabs blocks. */ function quicktabs_block_delete_submit($form_id, $form_values) { db_query('DELETE FROM {quicktabs} WHERE qtid = %d', $form_values['qtid']); drupal_set_message(t('The Quick Tabs block %name has been removed.', array('%name' => $form_values['qt_name']))); cache_clear_all(); return 'admin/build/quicktabs'; }; /** * Callback function for admin/settings/quicktabs. Display the settings form. */ function quicktabs_settings() { $form = array(); $form['quicktabs_tabstyle'] = array( '#type' => 'radios', '#title' => t('Tab Style'), '#options' => array('default' => t('Default (no style)')) + module_invoke_all('quicktabs_tabstyles'), '#default_value' => variable_get('quicktabs_tabstyle', 'default'), '#description' => t('Choose a tab style for your Quick Tabs blocks.'), '#attributes' => array('class' => 'quicktabs-tabstyles clear-block'), ); return system_settings_form($form); } function theme_quicktabs_settings($form) { quicktabs_add_css(); drupal_set_title(t('Quick Tabs Settings')); // Default preview. $form['quicktabs_tabstyle']['default']['#description'] = 'Default '. t('Preview') .':
'; // Preview for each style. $tabstyle_number = 0; foreach (element_children($form['quicktabs_tabstyle']) as $tabstyle_key) { if ($tabstyle_key != 'default') { $form['quicktabs_tabstyle'][$tabstyle_key]['#description'] = $form['quicktabs_tabstyle'][$tabstyle_key]['#title'] .' '. t('Preview') .':
'; $tabstyle_number++; } } return drupal_render($form); } /** * Callback function for quicktabs/preview. */ function quicktabs_preview_page($tabstyle_number = NULL) { $tabstyles = module_invoke_all('quicktabs_tabstyles'); $css_files = array_keys($tabstyles); if (isset($css_files[$tabstyle_number])) { quicktabs_add_css($css_files[$tabstyle_number]); } else { quicktabs_add_css('default'); } drupal_add_js(drupal_get_path('module', 'quicktabs') .'/js/quicktabs.js'); print theme('quicktabs_preview_page'); exit; } function theme_quicktabs_preview_page() { $output = "\n"; $output .= ''; $output .= ''; $output .= ' '. t('Quick Tabs Preview') .''; $output .= drupal_get_html_head(); $output .= drupal_get_css(); $output .= drupal_get_js(); $output .= ' '; $output .= ' '; $output .= '
'; $output .= ''; $output .= '
'; $output .= ''; return $output; } /** * Fetch the necessary CSS files for the tab styles. */ function quicktabs_add_css($tabstyle_css = NULL) { // Add quicktabs CSS. drupal_add_css(drupal_get_path('module', 'quicktabs') .'/quicktabs.css'); // Add specific CSS. if (!isset($tabstyle_css)) { $tabstyle_css = variable_get('quicktabs_tabstyle', 'default'); } if ($tabstyle_css != 'default') { drupal_add_css($tabstyle_css, 'module'); } } /** * Implementation of hook_quicktabs_widgets. * * This hook allows other modules to create additional tab styles for * the quicktabs module. * * @return array * An array of key => value pairs suitable for inclusion as the #options in a * select or radios form element. Each key must be the location of a css * file for a quick tabs style. Each value should be the name of the style. */ function quicktabs_quicktabs_tabstyles() { $tabstyles_directory = drupal_get_path('module', 'quicktabs') .'/tabstyles'; $files = file_scan_directory($tabstyles_directory, '\.css$'); $tabstyles = array(); foreach ($files as $file) { $tabstyles[$file->filename] = drupal_ucfirst($file->name); } return $tabstyles; }