I would like to use this module for the user edit form, but not for the registration form. Is there some way I can programmatically disable the module for the registration form, or enable/disable it based on the URL? What would be the cleanest way to do that? Thank you

CommentFileSizeAuthor
#7 28-09-2013 11-05-38.jpg57.01 KBfugazi
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

arnoldbird’s picture

Initially it looks like my best bet might be to work with CSS. For example, override the following CSS at URLs where I don't want the field_group module to affect output:

.horizontal-tabs .horizontal-tab-hidden {
display: block;
position: absolute;
top: -100000px;
}

That's in horizontal-tabs.css. I'm using horizontal tabs at the moment.

In other words, I need to un-hide some hidden fieldsets. I'll also need to hide the tabs, of course.

This is a very useful module.

arnoldbird’s picture

Actually, my solution in #1 is a bad solution, because it hides the fieldsets but doesn't really disable them. They're still there, in the HTML, and this makes it impossible to re-order the fields programmatically in a hook_form_alter -- unless you only want to re-order them within the fieldset but not move them out of a fieldset.

I'm still poking around in field_group.module, hoping there is some way to disable this module entirely for some form_ids or URLs, while still using it in other situations.

arnoldbird’s picture

I feel like the answer must lie in the module's pre_render functions? Looks like the functions in field_group.api.php are intended as a way for other modules to intervene, but I'm not sure how.

arnoldbird’s picture

I have it narrowed down to one line in field_group_pre_render_tab().

Around line 826...

$add = array(
    '#type' => 'fieldset',

If I comment out that second line so the type is never set to fieldset, then the fieldsets don't render as vertical tabs. Instead, all fieldsets are displayed in series, sans tabs. So I just need to figure out how to unset that #type from my module. hook_form_alter doesn't seem to provide any opportunity to do this. This seems to be happening later in the processing. I also tried playing with the pre_render functions in the module's api file, but have not had any luck with that. Maybe hook_page_alter is something to try.

I did find a way to control the ordering of the fieldsets in hook_form_alter:

$form['#groups']['some_group_name']->weight = 123;

arnoldbird’s picture

In my theme:

function mytheme_css_alter(&$css) {
  if ('user/register' == current_path()) {
    unset($css['misc/vertical-tabs.css']);
  }
}
function mytheme_form_alter(&$form, &$form_state, $form_id) { 
  if ('user_register_form' == $form_id) {
    drupal_add_js(drupal_get_path('theme', 'mytheme') . '/scripts/forms.js');
  }
}

forms.js:

(function($) {
  Drupal.behaviors.somebehavior = {
  attach: function(context, settings) { 
    $('.field-group-tab').attr('style', 'display: block;');
    $('.vertical-tabs-list').attr('style', 'display: none;');
    $('.fieldset-legend').attr('style', 'display: none;');
  }
  }
})(jQuery);

The above removes the surface effects of field_group for a particular form, but does not actually remove the groups. Groups can be re-ordered, though, by setting the weight as shown in #4. With that, for just about all intents and purposes, field_group is not in effect for a particular form.

xcafebabe’s picture

The next code worked for me

function MYMODULE_form_alter(&$form, &$form_state, $form_id) { 
  if ('user_register_form' == $form_id) {
    //Empty Group Children Relationship Array
    $form['#group_children'] = array();
  }
}
fugazi’s picture

FileSize
57.01 KB

# 6 does not work. Have it inserted in the template.php. I need to add something else. I want the user profile settings to groups not only let in the register.

fugazi’s picture

ups it works, after a server restart everything is ok

MXT’s picture

#6 works very well: thank you xcafebabe!

W01F’s picture

Hmm... also tried inserting this snippet into template.php, but can't get it to work. First I tried it with "function MYMODULE_form_alter" but guessed that was wrong. So I changed it to "function field_group_form_alter" - but that doesn't seem to work either. Any suggestions for what I'm doing incorrectly? Thanks!

fugazi’s picture

@WOLF maybe you have forgotten "mymodule", to change in your theme name.

function my_themes_name_form_alter(&$form, &$form_state, $form_id) { 
  if ('user_register_form' == $form_id) {
    //Empty Group Children Relationship Array
    $form['#group_children'] = array();
  }
}

my_themes_name e.g. bartik = bartik_form_alter

nils.destoop’s picture

Issue summary: View changes
Status: Active » Closed (fixed)