Same name in other branches
- 8.x-1.x quicktabs.module \quicktabs_build_quicktabs()
Constructs a Quicktabs instance.
This function can be called by other modules to programmatically build a quicktabs instance.
Paramètres
name. The machine name of the Quicktabs instance to build - if a name: is passed that does not correspond to an existing instance, then it is taken to be a completely custom instance and is built from only the custom tabs that are passed in.
settings. An array of settings that will override the options of the Quicktabs: instance from the database, or if no existing instance is being used, these will override the default settings. Possible keys are 'style', 'hide_empty_tabs', ajax', 'default_tab', 'renderer', 'title' and 'options'.
custom_tabs. An array representing custom tab contents, which will be: appended to the Quicktabs instance from the database, or if no existing instance is being used, the custom tabs will be the entire contents. An example custom_tabs array would be array(array('title' => 'custom', 'contents' => array('#markup' => t('Some markup'), 'weight' => 5));
Return value
A render array that can be used as block content in hook_block_view (see quicktabs_block_view()), but can also just be added to the page array during hook_page_alter, or output anywhere else where it's sure to get passed through drupal_render().
3 calls to quicktabs_build_quicktabs()
- quicktabs_block_view dans ./
quicktabs.module - Implements hook_block_view().
- quicktabs_style_plugin::render dans includes/
quicktabs_style_plugin.inc - theme_quicktabs_style_options dans quicktabs_tabstyles/
quicktabs_tabstyles.module - Theme function for quicktabs style radio options.
Fichier
-
./
quicktabs.module, line 185
Code
function quicktabs_build_quicktabs($name, $settings = array(), $custom_tabs = array()) {
if ($info = quicktabs_load($name)) {
// Allow other modules to alter the Quicktabs instance before it gets output.
drupal_alter('quicktabs', $info);
$info = (array) $info;
$settings = array_merge($info, $settings);
$contents = $settings['tabs'];
unset($settings['tabs'], $settings['machine_name']);
}
elseif (!empty($custom_tabs)) {
// We'll be creating a custom Quicktabs instance. Make sure we're using an
// alphanumeric name.
$name = preg_replace('/[^[a-zA-Z]_]/', '_', $name);
$contents = array();
}
else {
// If $name doesn't correspond to an existing Quicktabs instance, and there
// are no custom tabs to render, then we have nothing to do.
return array();
}
$renderer = isset($settings['renderer']) ? $settings['renderer'] : 'quicktabs';
unset($settings['renderer']);
$needs_sorting = FALSE;
$weight = 0;
foreach ($custom_tabs as &$tab) {
$needs_sorting = $needs_sorting || isset($tab['weight']);
$tab += array(
'type' => 'prerendered',
'weight' => $weight++,
);
}
$contents = array_merge($custom_tabs, $contents);
$weight = array();
foreach ($contents as $key => $item) {
// Load the plugin responsible for rendering this item, if it is not a
// prerendered tab.
if ($item['type'] != 'prerendered') {
ctools_plugin_load_class('quicktabs', 'contents', $item['type'], 'handler');
}
// Add item's weight to our weights array so that we can then sort by weight.
$weight[$key] = $item['weight'];
// Make sure we're not going to try to load the same QuickSet instance
// inside itself.
if ($item['type'] == 'qtabs' && $item['machine_name'] == $name) {
unset($contents[$key]);
unset($weight[$key]);
}
}
// Only sort by weight if the tabs haven't already been sorted by some other
// mechanism, e.g. Views in the case of the Views style plugin and there was
// a weight given for one of the tabs.
if ($needs_sorting && (!isset($settings['sorted']) || !$settings['sorted'])) {
array_multisort($weight, SORT_ASC, $contents);
}
else {
unset($settings['sorted']);
}
if ($qt = quickset_renderer_factory($name, $contents, $renderer, $settings)) {
$renderable_qt = array(
'#title' => $qt->getTitle(),
'content' => $qt->render(),
);
return $renderable_qt;
}
return array();
}