field_group.features.inc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Implements hook_features_export_alter().
  4. *
  5. * For a given feature, add field groups that contain any fields that
  6. * are a part of this feature. Also, add parent groups of any groups
  7. * that are a part of this feature.
  8. */
  9. function field_group_features_export_alter(&$export, $module_name) {
  10. //Make sure we have fresh data by loading directly.
  11. ctools_include('export');
  12. $field_groups = ctools_export_load_object('field_group');
  13. //Add fieldgroups based on the fields that are present.
  14. if (!empty($export['features']['field'])) {
  15. foreach ($export['features']['field'] as $field) {
  16. list($entity_type, $bundle, $field_name) = explode('-', $field);
  17. foreach ($field_groups as $group_id => $group) {
  18. if ($group->entity_type == $entity_type && $group->bundle == $bundle
  19. && in_array($field_name, $group->data['children'])) {
  20. $export['features']['field_group'][$group_id] = $group_id;
  21. }
  22. }
  23. }
  24. }
  25. //Add any parent field groups that haven't been selected.
  26. if (!empty($export['features']['field_group'])) {
  27. foreach ($export['features']['field_group'] as $id) {
  28. $group = isset($field_groups[$id]) ? $field_groups[$id] : FALSE;
  29. if ($group && !empty($group->parent_name)) {
  30. $parent_id = $group->parent_name . '|' . $group->entity_type . '|' . $group->bundle . '|' . $group->mode;
  31. $parent_group = isset($field_groups[$parent_id]) ? $field_groups[$parent_id] : FALSE;
  32. if ($parent_group && !isset($export['features']['field_group'][$parent_id])) {
  33. $export['features']['field_group'][$parent_id] = $parent_id;
  34. }
  35. }
  36. }
  37. if(empty($export['dependencies']['field_group'])) {
  38. $export['dependencies']['field_group'] = 'field_group';
  39. }
  40. }
  41. }