Q: Is it possible to convert from the Vertical Tabs area of the form to the Field area? Scenario: I have a node type that can only show one of the Vertical Tabs to the user role ( Publishing Options "status" ), and hide all others. This creates a situation which looks like this:

Which is similar, but not the same, as the Accordion Items I have as fields above it.  So is there a way I can move these into the fields area via simple conversion? 

I have looked at what is available via DPM, and "status" is a direct Array, whereas the Accordianed Fields are Objects which have totally different mapping.

Most helpful answers

Hi onyx,

it's always possible to adapt forms by hook_form_FORM_ID_alter().

A simple example, as I don't know your setup:

function foobar_form_node_form_alter(&$form, &$form_state) {
  global $user;
  // Check for the current user's roles.
  if (!in_array('administrator', $user->roles)) {
    // Vertical tabs wrapper.
    $form['additional_settings']['#type'] = 'container';
    // The publishing options.
    $form['options']['#type'] = 'container';
    // Move the publishing options down in the form.
    $form['options']['#weight'] = 5;
  }
}

Where "foobar" should get replaced with the name of your custom module.

Above example may not fit your use-case 100%, but what it does:

  • Convert the wrapper from vertical tab to a regular div container.
  • Convert the publishing options to a regular div container.
  • Sets the weight of that field to move it further down.

You may need to adapt it for your setup, for example check the node type, check for a different role...

Comments

indigoxela's picture

Hi onyx,

it's always possible to adapt forms by hook_form_FORM_ID_alter().

A simple example, as I don't know your setup:

function foobar_form_node_form_alter(&$form, &$form_state) {
  global $user;
  // Check for the current user's roles.
  if (!in_array('administrator', $user->roles)) {
    // Vertical tabs wrapper.
    $form['additional_settings']['#type'] = 'container';
    // The publishing options.
    $form['options']['#type'] = 'container';
    // Move the publishing options down in the form.
    $form['options']['#weight'] = 5;
  }
}

Where "foobar" should get replaced with the name of your custom module.

Above example may not fit your use-case 100%, but what it does:

  • Convert the wrapper from vertical tab to a regular div container.
  • Convert the publishing options to a regular div container.
  • Sets the weight of that field to move it further down.

You may need to adapt it for your setup, for example check the node type, check for a different role...

Thanks, so this is my code:

if($rolevar AND 4){

$form['options']['#access']=true; //make sure the publishing options are available for the Coordinators

$form['options']['field_ready_to_publish'] = $form['field_ready_to_publish'];

unset($form['field_ready_to_publish']);

$form['options']['unpublish_on']=$form['scheduler_settings']['unpublish_on'];

$form['options']['field_ready_to_publish']['#weight'] =10;

$form['options']['unpublish_on']['#weight'] = 9;

unset($form['scheduler_settings']['unpublish_on']);

unset($form['scheduler_settings']);

// Vertical tabs wrapper.

$form['additional_settings']['#type'] = 'container';

// The publishing options.

$form['options']['#type'] = 'container';

// Move the publishing options down in the form.

$form['options']['#weight'] = 99;

}

What I am wanting is to get the Publishing Options inside an Accordion Group/Child. But looking at the $form dump of this, I cannot see how to choose the right #type.

indigoxela's picture

Your latest comments make me think, that I completely misunderstood your request. ;-)

However, what you call "Accordion" are fieldsets, they can have a "#collapsible" and "#collapsed" property which toggles their state.

Here's the documentation for fieldsets

From the screenshot alone, I can't tell whether these actually are fieldsets. Could also be details, or something provided by a module, but core provides form stuff in fieldsets.