3

I believe I am using the default Fieldgroup module. I have added a new group using "Add new group", then I have created a couple test fields and nested them under that group.

I see the entry is added in my 'field_group' table in my database. What I am wondering is how I can programmatically see that relationship. Please bear with me. After adding content I am using field_info_instance to view each field for that node. I do not see any field that shows a connection to the group I created. Is there a function that would let me see this relationship on a field by field basis??

Thank you,

2

I couldn't find one in the module anywhere but I cobbled this together and it seems to work ok:

function field_get_field_group($field) {
  $group_info = field_group_read_groups(array('entity_type' => $field['entity_type'], 'bundle' => $field['bundle']));
  foreach ($group_info[$field['entity_type']][$field['bundle']]['form'] as $group) {
    if (in_array($field['field_name'], $group->children)) {
      return $group;
    }
  }
  return FALSE;
}

Usage:

$field = field_info_instance('node', 'field_image', 'article');

if ($field_group = field_get_field_group($field)) {
  $group_name = $field_group->group_name;
  // etc...
}

You'll probably want to add some error checking ;)

  • thank you so much! field_group_read_groups was exactly what i'm looking for. There are so many functions in the api!!! ty – dm03514 Mar 27 '12 at 0:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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