I wrote a simple possible solution in the already mentioned thread: https://drupal.org/node/1048644#comment-7822687. For convenience, I'll paste it here.
There's a simple way to disable vertical tabs on a form, by simply changing the $form['additional_settings']['#type']
variable's value to 'fieldset'
in an implementation of hook_form_alter() or hook_form_FORM_ID_alter(), if it's equal to 'vertical_tabs'
.
You don't need to change the access settings or walk the whole $form
array recursively, the latter consumes unnecessarily too much resources.
(Tested in Drupal 7.23.)
/**
* Disable Vertical tabs on a form with simply changing the value of $form['additional_settings']['#type']
* @see https://drupal.org/node/1048644
*/
function form_disable_vertical_tabs(&$form){
// originally $form['additional_settings']['#type'] equals to 'vertical_tabs'
if(isset($form['additional_settings']['#type']) && ($form['additional_settings']['#type'] === 'vertical_tabs')){
$form['additional_settings']['#type'] = 'fieldset';
}
}
/**
* Implements hook_form_alter().
*/
function MYMODULEORTHEMENAME_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'my_form_id'){
// disable vertical tabs for this form
form_disable_vertical_tabs($form);
}
}
That's all, of course, substitute MYMODULEORTHEMENAME
to your own module's or theme's name (the latter in a template.php
file), and my_form_id
to your form's id.
You can also disable the vertical fields only for users who do NOT have the administrator role:
/**
* Implements hook_form_alter().
*/
function MYMODULEORTHEMENAME_form_alter(&$form, &$form_state, $form_id) {
global $user;
$is_administrator = in_array('administrator', array_values($user->roles));
if($form_id == 'my_form_id'){
// if $user does NOT have the administrator role.
if (!$is_administrator) {
// disable vertical tabs for this form
form_disable_vertical_tabs($form);
}
}
}
In case someone is interested, I attached a patch (which does the same as above) to Dripman's sandbox module: #2080739: Simplify the method of disabling Vertical tabs with just changing the $form['additional_settings']['#type']
to 'fieldset'
.