| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: features.fieldgroup.inc,v 1.1.2.7 2010/07/24 21:46:24 yhahn Exp $ 3 4 /** 5 * Implementation of hook_features_api(). 6 */ 7 function fieldgroup_features_api() { 8 return array( 9 'fieldgroup' => array( 10 'name' => t('Fieldgroup'), 11 'default_hook' => 'fieldgroup_default_groups', 12 'default_file' => FEATURES_DEFAULTS_INCLUDED, 13 ), 14 ); 15 } 16 17 /** 18 * Implementation of hook_features_export(). 19 */ 20 function fieldgroup_features_export($data, &$export, $module_name = '') { 21 features_include_defaults('fieldgroup'); 22 $pipe = array(); 23 24 // The hook_fieldgroup_default_groups() hook integration is provided by the 25 // features module so we need to add it as a dependency. 26 $export['dependencies']['features'] = 'features'; 27 28 // Collect a group to module map 29 $map = features_get_default_map('fieldgroup', NULL, 'fieldgroup_features_identifier'); 30 foreach ($data as $instance) { 31 // If this group is already provided by another module, remove the group 32 // and add the other module as a dependency. 33 if (isset($map[$instance]) && $map[$instance] != $module_name) { 34 if (isset($export['features']['fieldgroup'][$instance])) { 35 unset($export['features']['fieldgroup'][$instance]); 36 } 37 $module = $map[$instance]; 38 $export['dependencies'][$module] = $module; 39 } 40 // If the group has not yet been exported, add it. 41 else { 42 $split = explode('-', $instance); 43 $type_name = $split[0]; 44 $group_name = $split[1]; 45 $groups = fieldgroup_groups($type_name, FALSE, TRUE); 46 47 if (isset($groups[$group_name]) && $group = $groups[$group_name]) { 48 $export['features']['fieldgroup'][$instance] = $instance; 49 $export['dependencies']['fieldgroup'] = 'fieldgroup'; 50 } 51 } 52 } 53 54 return $pipe; 55 } 56 57 /** 58 * Implementation of hook_features_export_render(). 59 */ 60 function fieldgroup_features_export_render($module, $data) { 61 $translatables = $code = array(); 62 63 $code[] = ' $groups = array();'; 64 $code[] = ''; 65 foreach ($data as $instance) { 66 $instance = explode('-', $instance); 67 $type_name = $instance[0]; 68 $group_name = $instance[1]; 69 $groups = fieldgroup_groups($type_name, FALSE, TRUE); 70 if (isset($groups[$group_name]) && $group = $groups[$group_name]) { 71 // Clean up the fields to only list the names. 72 $group['fields'] = array_keys((array) $group['fields']); 73 74 $group_identifier = features_var_export(fieldgroup_features_identifier($group)); 75 $group_export = features_var_export($group, ' '); 76 $code[] = " // Exported group: {$group_name}"; 77 $code[] = " \$groups[{$group_identifier}] = {$group_export};"; 78 $code[] = ""; 79 80 // Add any labels to translatables array. 81 if (!empty($group['label'])) { 82 $translatables[] = $group['label']; 83 } 84 } 85 } 86 if (!empty($translatables)) { 87 $code[] = features_translatables_export($translatables, ' '); 88 } 89 $code[] = ' return $groups;'; 90 $code = implode("\n", $code); 91 return array('fieldgroup_default_groups' => $code); 92 } 93 94 /** 95 * Implementation of hook_features_revert(). 96 */ 97 function fieldgroup_features_revert($module) { 98 fieldgroup_features_rebuild($module); 99 } 100 101 /** 102 * Implementation of hook_features_rebuild(). 103 * Rebuilds CCK fieldgroup definitions from code defaults. 104 */ 105 function fieldgroup_features_rebuild($module) { 106 if ($groups = features_get_default('fieldgroup', $module)) { 107 content_clear_type_cache(TRUE); 108 109 foreach ($groups as $group) { 110 $type_name = $group['type_name']; 111 $group_name = $group['group_name']; 112 $groups = fieldgroup_groups($type_name, FALSE, TRUE); 113 114 if (isset($groups[$group_name])) { 115 $existing_group = $groups[$group_name]; 116 // Only field names are exported in fieldgroup_features_export_render(), so we 117 // update the existing group to match. 118 $existing_group['fields'] = array_keys($existing_group['fields']); 119 } 120 121 // No need to rebuild if the group already exists and is identical. 122 if ($existing_group != $group) { 123 // Update each field from this group. 124 foreach ($group['fields'] as $field_name) { 125 if ($field = content_fields($field_name, $type_name)) { 126 $field['group'] = $group_name; 127 fieldgroup_update_fields($field); 128 } 129 } 130 131 // Look in the old group for any fields that have been removed. 132 if ($existing_group && !empty($existing_group['fields'])) { 133 foreach($existing_group['fields'] as $field_name) { 134 // We only want to update the field if the field no longer exists in the group 135 // and the field's existing group name matches the group currently being rebuilt. 136 if ( 137 !in_array($field_name, $group['fields']) && 138 _fieldgroup_field_get_group($type_name, $field_name) == $group_name && 139 $field = content_fields($field_name, $type_name) 140 ) { 141 $field['group'] = ''; 142 fieldgroup_update_fields($field); 143 } 144 } 145 } 146 147 fieldgroup_save_group($type_name, $group); 148 variable_set('menu_rebuild_needed', TRUE); 149 } 150 } 151 } 152 } 153 154 /** 155 * Callback for generating an identifier for a fieldgroup. 156 */ 157 function fieldgroup_features_identifier($object) { 158 return isset($object['type_name'], $object['group_name']) ? "{$object['type_name']}-{$object['group_name']}" : FALSE; 159 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |