1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
/**
|
5 |
|
|
* Implements hook_features_export_alter().
|
6 |
|
|
*
|
7 |
|
|
* For a given feature, add field groups that contain any fields that
|
8 |
|
|
* are a part of this feature. Also, add parent groups of any groups
|
9 |
|
|
* that are a part of this feature.
|
10 |
|
|
*/
|
11 |
|
|
function field_group_features_export_alter(&$export, $module_name) {
|
12 |
|
|
// Make sure we have fresh data by loading directly.
|
13 |
|
|
ctools_include('export');
|
14 |
|
|
$field_groups = ctools_export_load_object('field_group');
|
15 |
|
|
|
16 |
|
|
// Support the separate field base -vs- field instance structure that was
|
17 |
|
|
// added in Features v7.x-2.0-beta2.
|
18 |
|
|
if (function_exists('field_instance_features_export')) {
|
19 |
|
|
$export_var = 'field_instance';
|
20 |
|
|
}
|
21 |
|
|
else {
|
22 |
|
|
$export_var = 'field';
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
// Add fieldgroups based on the fields that are present.
|
26 |
|
|
if (!empty($export['features'][$export_var])) {
|
27 |
|
|
if (!isset($export['features']['field_group'])) {
|
28 |
|
|
$export['features']['field_group'] = array();
|
29 |
|
|
}
|
30 |
|
|
foreach ($export['features'][$export_var] as $field) {
|
31 |
|
|
list($entity_type, $bundle, $field_name) = explode('-', $field);
|
32 |
|
|
|
33 |
|
|
foreach ($field_groups as $group_id => $group) {
|
34 |
|
|
|
35 |
|
|
if ($group->entity_type == $entity_type && $group->bundle == $bundle && in_array($field_name, $group->data['children']) && !in_array($group->identifier, $export['features']['field_group'])) {
|
36 |
|
|
if (isset($group->export_module) && $group->export_module != $module_name) {
|
37 |
|
|
$export['dependencies'][$group->export_module] = $group->export_module;
|
38 |
|
|
}
|
39 |
|
|
else {
|
40 |
|
|
$export['features']['field_group'][$group_id] = $group_id;
|
41 |
|
|
}
|
42 |
|
|
}
|
43 |
|
|
}
|
44 |
|
|
}
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
// Add any parent field groups that haven't been selected.
|
48 |
|
|
if (!empty($export['features']['field_group'])) {
|
49 |
|
|
foreach ($export['features']['field_group'] as $id) {
|
50 |
|
|
$group = isset($field_groups[$id]) ? $field_groups[$id] : FALSE;
|
51 |
|
|
|
52 |
|
|
if ($group && !empty($group->parent_name)) {
|
53 |
|
|
$parent_id = $group->parent_name . '|' . $group->entity_type . '|' . $group->bundle . '|' . $group->mode;
|
54 |
|
|
$parent_group = isset($field_groups[$parent_id]) ? $field_groups[$parent_id] : FALSE;
|
55 |
|
|
|
56 |
|
|
if ($parent_group && !isset($export['features']['field_group'][$parent_id])) {
|
57 |
|
|
if (isset($parent_group->export_module) && $parent_group->export_module != $module_name) {
|
58 |
|
|
$export['dependencies'][$parent_group->export_module] = $parent_group->export_module;
|
59 |
|
|
}
|
60 |
|
|
else {
|
61 |
|
|
$export['features']['field_group'][$parent_id] = $parent_id;
|
62 |
|
|
}
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
}
|
66 |
|
|
if(empty($export['dependencies']['field_group'])) {
|
67 |
|
|
$export['dependencies']['field_group'] = 'field_group';
|
68 |
|
|
}
|
69 |
|
|
}
|
70 |
|
|
} |