Drupal - Disable vertical tabs by content type or user role

There are few ways to do this:

  1. You can use the Renderable Elements module (as you mentioned above). It enables you to register any piece of build on your installation and manage the display through Field UI. It will make (additional) elements available of existing entities on the manage forms/display screens or you can for example register the contact form and rearrange the fields through Field UI. Works currently fine on forms, support for other is coming in a second iteration.

  2. Or add the following to your custom module:

    $config['yourcontenttype_node_form'] = FALSE;
    variable_set('vertical_tabs_forms', $config);
    
  3. A sandbox module that disables vertical tabs

Here is this core issue that refers to this.


You can also use the #access check to keep people from seeing the vertical tabs.

$form['additional_settings']['#access'] = FALSE;

Simply add that to a hook form alter or in between the loading and the rendering of a form. After that you can call render($form) to get the markup.


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'.