function fieldgroup_features_rebuild in Features 6
Implementation of hook_features_rebuild(). Rebuilds CCK fieldgroup definitions from code defaults.
1 call to fieldgroup_features_rebuild()
- fieldgroup_features_revert in includes/
features.fieldgroup.inc - Implementation of hook_features_revert().
File
- includes/
features.fieldgroup.inc, line 107
Code
function fieldgroup_features_rebuild($module) {
if ($groups = features_get_default('fieldgroup', $module)) {
content_clear_type_cache(TRUE);
foreach ($groups as $group) {
$type_name = $group['type_name'];
$group_name = $group['group_name'];
$groups = fieldgroup_groups($type_name, FALSE, TRUE);
if (isset($groups[$group_name])) {
$existing_group = $groups[$group_name];
// Only field names are exported in fieldgroup_features_export_render(), so we
// update the existing group to match.
$existing_group['fields'] = array_keys($existing_group['fields']);
}
// No need to rebuild if the group already exists and is identical.
if ($existing_group != $group) {
// Update each field from this group.
foreach ($group['fields'] as $field_name) {
if ($field = content_fields($field_name, $type_name)) {
$field['group'] = $group_name;
fieldgroup_update_fields($field);
}
}
// Look in the old group for any fields that have been removed.
if ($existing_group && !empty($existing_group['fields'])) {
foreach ($existing_group['fields'] as $field_name) {
// We only want to update the field if the field no longer exists in the group
// and the field's existing group name matches the group currently being rebuilt.
if (!in_array($field_name, $group['fields']) && _fieldgroup_field_get_group($type_name, $field_name) == $group_name && ($field = content_fields($field_name, $type_name))) {
$field['group'] = '';
fieldgroup_update_fields($field);
}
}
}
fieldgroup_save_group($type_name, $group);
variable_set('menu_rebuild_needed', TRUE);
}
}
}
}