11

Some users may only have the ability to edit one of the fieldsets that shows up in vertical tabs on the node edit form. In such a case it looks rather silly to be using vertical tabs since there is only one vertical tab to choose from. See screenshot:

screenshot

So, is it possible to disable vertical tabs by user role? Or, barring that, disable them altogether for certain content types? For my use case I just want Location to not be displayed in vertical tabs.

I tried Renderable Fields and Field Group together but they managed the form incorrectly (buggy, I think). Arrange Fields can't separate out Vertical Tabs.

1
  • Did you ever fix this? Trying to do the same with ubercart product tab.
    – Dee
    Apr 27, 2013 at 15:47

7 Answers 7

7

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.

7
  • As I said in the question, Renderable Elements isn't working for me. It's still in alpha stage and there's a known bug with Location. So it doesn't work for my situation. Otherwise, yes, I think this would work. If in the future that bug gets fixed, Renderable Elements is probably the best way to go about this.
    – Jay
    Jan 25, 2012 at 17:59
  • sorry I just skimmed your question and completely missed your reference to the renderable elements module. That being said, the dev version works like a charm. Give that a go.
    – user842
    Jan 25, 2012 at 18:02
  • Hmm, ok. I'll try using the dev version if there are no other alternatives. Leaving this open for now.
    – Jay
    Jan 25, 2012 at 18:06
  • I have modified my answer above with more options.
    – user842
    Jan 25, 2012 at 18:12
  • 1
    You are right. I just tried it and this doesn't work in D7 as it did in D6. Unfortunately if renderable elements doesn't work and your not comfortable with your own module or using the sandbox module, I am not sure what else.
    – user842
    Jan 25, 2012 at 19:36
6

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.

2

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

1
  • Excellent solution, @Sk8erPeter. I wonder if it's possibly to hide the additional settings without setting '#access' = FALSE, as this loses the values that would be set by the default settings, such as the url alias and published status.
    – Jav
    Mar 18, 2014 at 23:30
0

Render-able elements is not currently supported, and acknowledges on the project page that it clashes with some other contributed modules so I wouldn't rely on it for production sites.

The question of how to disable vertical tabs completely is tackled in this thread.

Dripman has created a simple sandbox module to disable vertical tabs completely.

Depending on your desired level of engagement with coding, Dripman's module should be easily customisable to be selective on the basis of fields/roles.

Apologies for overlap with succinct answer by @nicoz

0

You can use the module Vertical Tabs Visibility.

This module helps to manage vertical tabs visibility on content type add/edit forms.

To manage vertical tabs visibility on content type add/edit forms. simply visit /admin/config/user-interface/vertical-tabs-visibility page and select content types. Vertical tabs at node add/edit form will be disabled for checked content types.

Currently module is in sandbox

0

For my use case, I was trying to disable the vertical tabs being applied on the Publishing options section on a node edit form (since this was the only fieldset a particular set of users have access to):

// Place somewhere in MYMODULE_form_alter()...
$form['additional_settings']['#type'] = 'fieldset';
$form['additional_settings']['#collapsible'] = FALSE;
$form['options']['#collapsible'] = FALSE;

For clarification, not only do you need to set additional_settings #collapsible to FALSE, any elements within must also have #collapsibleset toFALSE, in my case that was theoptions` element.

0

There's the Vertical Tabs Config module which offers hiding some or all tabs by role or for all users.

This module allows you to:

  • Hide vertical tabs on add/edit node pages depending on content type and role.
  • Decide vertical tabs order (with a drag and drop interface since version 1.2).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.