I have formatted my field sets in a form builder function to display as vertical tabs. Here's a snippet of my code. It works fine:
$form['vertical_tabs'] = array(
'#type' => 'vertical_tabs',
);
// * Form elements: fieldset tree.
$form['episode'] = array(
'#title' => t('Episode details'),
'#type' => 'fieldset',
'#tree' => TRUE,
'#collapsible' => TRUE,
'#group' => 'vertical_tabs',
);
I see a lot of vertical tabs with, let's call it, a menu subtitle just below the menu title. It's the grey text under the blue anchor text in this pic from the vertical_tabs module page - the top one reads 'Create new revision':
I guessed, wrongly, that adding a #description attribute with my menu subtitle would add it in, but is just appears at the top the field sets' tab contents. Does anyone know how this is done?
Thanks
SOLUTION
Some may consider this not to be the 'correct' Drupal way, but this is simple, requires hardly any code, resides in the Sites folder (so it won't be over written on update), and does not require editing any core files. Just a bit of CSS. This is what I did:
.vertical-tabs ul.vertical-tabs-list li:nth-child(1) .summary:after {
content: 'Menu subtitle 1';
}
.vertical-tabs ul.vertical-tabs-list li:nth-child(2) .summary:after {
content: 'Menu subtitle 2';
}
Clive's answer (see below) may be a better option if you're handy with JavaScipt.
ANOTHER SOLUTION
Here, is a jQuery solution I've developed:
Add this jQuery file to your module directory, call it jquery.YOURFILE.js:
/**
* Vertical tabs summary setters.
*/
(function( $ ) {
$(function() {
$( ".summary:gt(0)" ).html( "Foo" );
$( ".summary:gt(2)" ).html( "Bar" );
});
})( jQuery );
Here I used the .gt
method, but you could target tabs individually with the .eq
method. In your form element definition, where you define your fieldsets, add:
'#attached' => array(
'js' => array(drupal_get_path('module', 'YOURMODULE') . '/jquery.YOURFILE.js'),
),
MORE SOURCES OF INFORMATION
See the vertical_tabs examples module for another way to do this.
Look in content_types.inc and content_types.js in the node module too.
This is an update of the jQuery file above. It uses Drupal.behaviors and the eq method. Probably more 'correct' than the one above.
(function ($) {
Drupal.behaviors.yourModule = {
attach: function (context) {
$( ".summary:eq(0)" ).html( "Foo" );
$( ".summary:eq(1)" ).html( "Bar" );
$( ".summary:eq(2)" ).html( "Baz" );
}
};
})(jQuery);