Since beta6 the way to configure the tab visibility in vertical tabs is:

- Using settings.php: $conf['vertical_tabs_forms']['page_node_form'] = array('menu' => FALSE);

- Using form module.

But if you would like to set in your custom module the configuration for forms with fieldsets or altering the default vertical tabs configuration with all the fieldsets in vertical tabs for node and node type forms,
there is no way because using the $form['#pre_render'][] = 'vertical_tabs_form_pre_render'; only works with forms that you are defining in your module.

I propose to add the standars drupal alter to make changes in default configuration or adding new settings,
this way with a hook_vertical_tabs_alter(&$forms) you are able to manage the configuration.

An example for the hook_vertical_tabs_configuration that should be in your custom module:

/**
* Implements hook_vertical_tabs_alter().
*/
function YOUR_MODULE_vertical_tabs_alter(&$forms) {
  $forms['uprofile_node_form'] = array(
    'group_about' => FALSE,
    'notifications' => FALSE,
  );
  $forms['taxonomy_form_vocabulary'] = array('fake_fieldset_to_activate_form' => FALSE);

  );
}

In the first case you add vertical forms to the content profile module for uprofile content types (with the form module there is no way to configure this content type):
* Notifications fieldset is not added to vertical tabs
* and group_about fieldset (a cck fieldgroup) is not added in the vertical tabs (allowing even to show cck fieldgroup tabs with vertical tabs in the same form).

The second $forms['taxonomy_form_vocabulary'] adds vertical tabs to the drupal system vocabulary add form, but you need to have a not empty array.

This way you can customize forms that don't work yet with the form module, you can add new forms with vertical tabs, and all this saved in a custom module.

Comments

jcmarco’s picture

For activating forms with fieldsets, it is just needed:

$forms['taxonomy_form_vocabulary'] = TRUE;

dave reid’s picture

Interesting idea. I just modified vertical_tabs_form_alter() so you can do this:

function mymodule_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'uprofile_node_form') {
    $form['#vertical_tabs'] = array('group_about' => 0, 'notifications' => 0);
  }
  elseif ($form_id == 'taxonomy_form_volcabulary') {
    $form['#pre_render'] = 'vertical_tabs_form_pre_render';
  }
}

I'm also going to be adding support for the #group parameter for fieldsets that if it is FALSE or empty, it will not be included in vertical tabs by default.

jcmarco’s picture

I have tested last dev version with form_alter's but there is a problem

line 34:
elseif ($config) {
$form['#vertical_tabs'] = is_array($config) ? $config : array();

it overrides any $form['#vertical_tabs'] that you have added in your custom_form_alter so it needs a patch like:

line 34:
elseif ($config) {
$form['#vertical_tabs'] += is_array($config) ? $config : array();

But if $form['#vertical_tabs'] was not defined previouly then there is a bug so:
$form['#vertical_tabs'] = isset($form['#vertical_tabs']) ? $form['#vertical_tabs'] : array();
$form['#vertical_tabs'] += is_array($config) ? $config : array();

Other option would be to allow override even the default config for content types and admin menus, with something like this:
$form['#vertical_tabs'] = isset($form['#vertical_tabs']) ? $form['#vertical_tabs'] : array();
$form['#vertical_tabs'] = array_merge((is_array($config) ? $config : array()),$form['#vertical_tabs']);
$form['#vertical_tabs'] = array_unique($form['#vertical_tabs']);

NOTE:
For documentation purposes to add vertical tabs to any existing form with fieldsets the required change is:
$form['#pre_render'] []= 'vertical_tabs_form_pre_render';
With the [], to add this pre_render to other existing ones and not delete them

jcmarco’s picture

StatusFileSize
new722 bytes

Patch to add compatibility for custom vertical tabs configuration through hook_form_alter functions

gpiersol’s picture

I hope I'm not hijacking this thread but I wanted to say thanks for such a great module and for your usage instructions.

I've used vertical tabs and the above form_alter instructions from #2 to make a custom module to make a new fieldset encompassing all of the node admin options, like menu, author, path, etc.

I'm new to Drupal and to PHP so I honestly don't understand the other information in this thread (#3, #4). I'm wondering if either of you can confirm that I'm not making any errors in my usage:


if ($user->uid == 1 || in_array('webmaster', array_values($GLOBALS['user']->roles)) !== FALSE) {    

// Admin fieldset 	
	$form['customset-admin'] = array(
		'#type' => 'fieldset',
		'#title' => t('Admin Options'),
		'#weight' => 20,
		'#collapsible' => FALSE,
		'#collapsed' => FALSE,
		'#tree' => TRUE,
		);		
		
// Copy $form['various'] into $form['customset-admin']

       $form['customset-admin']['menu'] = $form['menu'];
       $form['customset-admin']['revision_information'] = $form['revision_information'];
       $form['customset-admin']['attachments'] = $form['attachments'];
       $form['customset-admin']['comment_settings'] = $form['comment_settings'];
       $form['customset-admin']['path'] = $form['path'];
       $form['customset-admin']['author'] = $form['author'];

// Vertical tab-ify

$form['#vertical_tabs'] = array('customset-admin' => 1);
}

// Remove default fields

unset($form['menu']);
unset($form['revision_information']);
unset($form['attachments']);
unset($form['comment_settings']);
unset($form['path']);
unset($form['author'])

From a usage point of view, this seems to work for me, but I want to be sure I'm understanding your instructions.

Thanks again!

Geoff

jcmarco’s picture

Status: Needs review » Fixed

I have seen that what I was patching it was already fixed in 9th Dec dev.

Now, you are able to override with form_alter but there is an issue with the #group check.
I will open in a new issue, as this feature is already included in the module and the problem is other.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.