2

I am trying to use #states on field_group at node add form.

From the search results I can find a couple of links which shows that hook_field_group_build_pre_render_alter() can make the magic but there is no luck for me.

I try to clear cache and dpm() some message inside the function. It seems the hook function has not been implemented at all.

These are the links I found.

0

2 Answers 2

1

I have gotten hook_field_group_build_pre_render_alter(&$element) to work. Without seeing an example of your code, it's hard to give any really helpful advice.

Here's an example for a nested fieldgroup made visible when a checkbox field is checked (the checkbox boolean field is "field_primary_not_caller"):

function MYMODULE_field_group_build_pre_render_alter(&$element) {
    //... Detect whether this is the right form...
    $element['group_contact']['group_primary_contact']['#states'] = array(
      'visible' => array(
        '#edit-field-primary-not-caller-und' => array('checked'=>TRUE),
      ),
    );
}

Finally, it's truly worthwhile to invest the time in getting xDebug up and running on your development machine - much better and easier to use than dpm()/var_dump()/etc, can save you hours with stuff like this.

1
  • Yes. xDebug is better but settings up xDebug is always a nightmare to me.
    – Jimmy Ko
    Apr 24, 2016 at 12:16
2

After debugging I found that hook_field_group_build_pre_render_alter() is indeed working, but dpm() cannot work inside it at all.

For debugging, you can only use var_dump() or kpr() inside this hook function.

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.