field_group.features.inc 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. // Support the separate field base -vs- field instance structure that was
  14. // added in Features v7.x-2.0-beta2.
  15. if (function_exists('field_instance_features_export')) {
  16. $export_var = 'field_instance';
  17. }
  18. else {
  19. $export_var = 'field';
  20. }
  21. // Add fieldgroups based on the fields that are present.
  22. if (!empty($export['features'][$export_var])) {
  23. if (!isset($export['features']['field_group'])) {
  24. $export['features']['field_group'] = array();
  25. }
  26. foreach ($export['features'][$export_var] as $field) {
  27. list($entity_type, $bundle, $field_name) = explode('-', $field);
  28. foreach ($field_groups as $group_id => $group) {
  29. if ($group->entity_type == $entity_type && $group->bundle == $bundle && in_array($field_name, $group->data['children']) && !in_array($group->identifier, $export['features']['field_group'])) {
  30. if (isset($group->export_module) && $group->export_module != $module_name) {
  31. $export['dependencies'][$group->export_module] = $group->export_module;
  32. }
  33. else {
  34. $export['features']['field_group'][$group_id] = $group_id;
  35. }
  36. }
  37. }
  38. }
  39. }
  40. // Add any parent field groups that haven't been selected.
  41. if (!empty($export['features']['field_group'])) {
  42. foreach ($export['features']['field_group'] as $id) {
  43. $group = isset($field_groups[$id]) ? $field_groups[$id] : FALSE;
  44. if ($group && !empty($group->parent_name)) {
  45. $parent_id = $group->parent_name . '|' . $group->entity_type . '|' . $group->bundle . '|' . $group->mode;
  46. $parent_group = isset($field_groups[$parent_id]) ? $field_groups[$parent_id] : FALSE;
  47. if ($parent_group && !isset($export['features']['field_group'][$parent_id])) {
  48. if (isset($parent_group->export_module) && $parent_group->export_module != $module_name) {
  49. $export['dependencies'][$parent_group->export_module] = $parent_group->export_module;
  50. }
  51. else {
  52. $export['features']['field_group'][$parent_id] = $parent_id;
  53. }
  54. }
  55. }
  56. }
  57. if(empty($export['dependencies']['field_group'])) {
  58. $export['dependencies']['field_group'] = 'field_group';
  59. }
  60. }
  61. }