t('Quicktab')),
array('data' => t('Storage')),
array('data' => t('Operations'), 'colspan' => $colspan),
);
$rows = array();
foreach (quicktabs_get_all_quicktabs() as $quicktab) {
if (module_exists('ctools')) {
// Determine storage
switch ($quicktab->export_type) {
case EXPORT_IN_DATABASE | EXPORT_IN_CODE:
$storage = t('Overridden');
$delete = l(t('Revert'), 'admin/structure/quicktabs/manage/'. $quicktab->machine_name .'/delete');
break;
case EXPORT_IN_DATABASE:
$storage = t('Normal');
$delete = l(t('Delete'), 'admin/structure/quicktabs/manage/'. $quicktab->machine_name .'/delete');
break;
case EXPORT_IN_CODE:
$storage = t('Default');
$delete = '';
break;
}
$tablerow = array(
array('data' => $quicktab->title),
array('data' => $storage),
array('data' => l(t('Edit'), 'admin/structure/quicktabs/manage/'. $quicktab->machine_name .'/edit')),
array('data' => l(t('Export'), 'admin/structure/quicktabs/manage/'. $quicktab->machine_name .'/export')),
array('data' => l(t('Clone'), 'admin/structure/quicktabs/manage/'. $quicktab->machine_name .'/clone')),
array('data' => $delete),
);
}
else {
$tablerow = array(
array('data' => $quicktab->title),
array('data' => t('Normal')),
array('data' => l(t('Edit'), 'admin/structure/quicktabs/manage/'. $quicktab->machine_name .'/edit')),
array('data' => l(t('Clone'), 'admin/structure/quicktabs/manage/'. $quicktab->machine_name .'/clone')),
array('data' => l(t('Delete'), 'admin/structure/quicktabs/manage/'. $quicktab->machine_name .'/delete')),
);
}
$rows[] = $tablerow;
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No quicktabs available.'), 'colspan' => $colspan + 2));
}
$build = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#attributes' => array('id' => 'quicktabs'),
);
return $build;
}
/**
* Clone QuickTabs.
*/
function quicktabs_clone($quicktab) {
unset($quicktab->machine_name);
$quicktab->title = '';
return drupal_get_form('quicktabs_form', 'clone', $quicktab);
}
/**
* Build the quicktab creation and edit form.
*/
function quicktabs_form($form, $form_state, $formtype, $quicktab = NULL) {
if (!isset($quicktab)) {
$quicktab = new stdClass;
}
$form = _quicktabs_admin_main_form($form_state, $quicktab);
if (empty($quicktab->tabs)) {
$quicktab->tabs = array(
0 => array(),
1 => array(),
);
}
// Add or remove tabs.
if (isset($form_state['num_tabs']) && $form_state['num_tabs'] > count($quicktab->tabs)) {
$quicktab->tabs[] = array();
}
$form_state['num_tabs'] = count($quicktab->tabs);
if (isset($form_state['to_remove'])) {
unset($quicktab->tabs[$form_state['to_remove']]);
unset($form_state['to_remove']);
$form_state['num_tabs']--;
}
$tab_titles = array();
// Add current tabs to the form.
foreach ($quicktab->tabs as $delta => $tab) {
$tab['delta'] = $delta;
$form['qt_wrapper']['tabs'][$delta] = _quicktabs_form($tab);
if (isset($tab['title'])) {
$tab_titles[$delta] = $tab['title'];
}
}
$form['default_tab'] = array(
'#type' => 'select',
'#title' => t('Default tab'),
'#options' => $tab_titles,
'#default_value' => isset($quicktab->default_tab) ? $quicktab->default_tab : 0,
'#access' => !empty($tab_titles),
'#weight' => -5,
);
return $form;
}
/**
* The main section of admin page.
*/
function _quicktabs_admin_main_form($form_state, &$quicktab) {
$form['#cache'] = TRUE;
// The contents of $quicktab will either come from the db or from $form_state.
if (isset($form_state['values']['title'])) {
$quicktab = _quicktabs_convert_form_to_quicktab($form_state);
}
if (empty($quicktab->machine_name)) {
$form['machine_name'] = array(
'#title' => t('Machine Name'),
'#type' => 'textfield',
'#description' => t('A unique ID that will be used internally and in the CSS ID of your quicktabs block. must contain only lowercase letters, numbers, and underscores.'),
'#default_value' => '',
'#weight' => -8,
'#required' => TRUE,
);
}
else {
$form['machine_name'] = array(
'#type' => 'value',
'#value' => $quicktab->machine_name,
);
$form['machine_name_display'] = array(
'#title' => t('Machine-readable name'),
'#type' => 'item',
'#value' => "{$quicktab->machine_name}
",
'#description' => t('The machine name will be used internally by quicktabs and will be used in the CSS ID of your quicktabs block.'),
'#weight' => -8,
);
}
$form['title'] = array(
'#title' => t('Block title'),
'#description' => t('This will appear as the name of this block in administer >> site building >> blocks.'),
'#type' => 'textfield',
'#default_value' => isset($quicktab->title) ? $quicktab->title : '',
'#weight' => -10,
'#required' => TRUE,
);
$styles = module_invoke_all('quicktabs_tabstyles');
$style_options = array();
// The keys used for options must be valid html id-s.
foreach ($styles as $style) {
$style_options[$style] = $style;
}
ksort($style_options);
$form['style'] = array(
'#type' => 'select',
'#title' => t('Style'),
'#options' => array('nostyle' => t('No style')) + array('default' => t('Default style')) + $style_options,
'#default_value' => isset($quicktab->style) ? $quicktab->style : 'default',
'#description' => t('Choose the quicktab style.'),
'#weight' => -8,
);
$form['ajax'] = array(
'#type' => 'radios',
'#title' => t('Ajax'),
'#options' => array(
TRUE => t('Yes') . ': ' . t('Load only the first tab on page view'),
FALSE => t('No') . ': ' . t('Load all tabs on page view.'),
),
'#default_value' => isset($quicktab->ajax) ? $quicktab->ajax : 0,
'#description' => t('Choose how the content of tabs should be loaded.
By choosing "Yes", only the first tab will be loaded when the page first viewed. Content for other tabs will be loaded only when the user clicks the other tab. This will provide faster initial page loading, but subsequent tab clicks will be slower. This can place less load on a server.
By choosing "No", all tabs will be loaded when the page is first viewed. This will provide slower initial page loading, and more server load, but subsequent tab clicks will be faster for the user. Use with care if you have heavy views.
'), '#weight' => -6, ); $form['hide_empty_tabs'] = array( '#type' => 'checkbox', '#title' => t('Hide empty tabs'), '#default_value' => isset($quicktab->hide_empty_tabs) ? $quicktab->hide_empty_tabs : 0, '#description' => t('Empty and restricted tabs will not be displayed. Could be useful when the tab content is not accessible.hook_quicktabs_default_quicktabs()
to provide it as a default quicktab.'),
);
$form['done'] = array(
'#type' => 'submit',
'#value' => t('Done'),
);
$form['#redirect'] = 'admin/structure/quicktabs';
return $form;
}
/**
* Helper function to get all blocks.
*/
function quicktabs_get_blocks() {
$blocksarray = &drupal_static(__FUNCTION__, array());
if (empty($blocksarray)) {
$blocks = _block_rehash();
$blocksarray = array();
foreach ($blocks as $block) {
if ($block['module'] != 'quicktabs') {
$key = $block['module'] . '_delta_' . $block['delta'];
$blocksarray[$key] = $block['info'] . ' (' . $block['module'] . ':' . $block['delta'] . ')';
}
}
}
return $blocksarray;
}
/**
* Ajax callback, triggered when view is changed.
*/
function _quicktabs_replace_view_displays_callback($form, $form_state) {
$view_name = $form_state['triggering_element']['#value'];
$delta = $form_state['triggering_element']['#parents'][1];
$display_options = _quicktabs_get_views_displays($view_name);
$form['qt_wrapper']['tabs'][$delta]['view']['display']['#options'] = $display_options;
$commands = array();
// Replace the view display dropdown.
$commands[] = ajax_command_replace("#view-display-dropdown-$delta", drupal_render($form['qt_wrapper']['tabs'][$delta]['view']['display']));
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* Helper function to get all views.
*/
function quicktabs_get_views() {
$enabled_views = array();
$views = views_get_all_views();
foreach ($views as $view) {
// Skip disabled views.
if (!empty($views[$view->name]->disabled)) {
continue;
}
$enabled_views[$view->name] = $view->name;
}
ksort($enabled_views);
return $enabled_views;
}
/**
* Helper function to get all view displays.
*/
function _quicktabs_get_views_displays($view_name) {
$displays = array();
if (empty($view_name)) {
// No view.
return $displays;
}
$views = views_get_all_views();
$view = $views[$view_name];
if (empty($view->display)) {
// This view is broken.
return $displays;
}
foreach ($view->display as $id => $display) {
$displays[$id] = $id .': '. $display->display_title;
}
return $displays;
}
/**
* Helper function to convert the data on admin form into quicktab presentation.
*/
function _quicktabs_convert_form_to_quicktab($form_state) {
$formvalues_tabs = array();
if (!empty($form_state['values']['tabs'])) {
foreach ($form_state['values']['tabs'] as $j => $tab) {
$formvalues_tabs[$j] = $tab[$tab['type']];
$formvalues_tabs[$j]['title'] = $tab['title'];
$formvalues_tabs[$j]['weight'] = $tab['weight'];
$formvalues_tabs[$j]['type'] = $tab['type'];
$weight[$j] = $tab['weight'];
}
array_multisort($weight, SORT_ASC, $formvalues_tabs);
}
$quicktab = new stdClass();
$quicktab->title = $form_state['values']['title'];
$quicktab->ajax = $form_state['values']['ajax'];
$quicktab->default_tab = isset($form_state['values']['default_tab']) ? $form_state['values']['default_tab'] : 0;
$quicktab->hide_empty_tabs = $form_state['values']['hide_empty_tabs'];
$quicktab->style = $form_state['values']['style'];
$quicktab->tabs = $formvalues_tabs;
if (isset($form_state['values']['machine_name'])) {
$quicktab->machine_name = $form_state['values']['machine_name'];
}
return $quicktab;
}