diff --git a/features.module b/features.module index d9ce8d6..a694009 100644 --- a/features.module +++ b/features.module @@ -629,6 +629,18 @@ function features_get_info($type = 'module', $name = NULL, $reset = FALSE) { if (!empty($row->info['scripts'])) { $row->info['scripts'] = array_keys($row->info['scripts']); } + // Rework the features array, to change the vocabulary permission + // features. + foreach ($row->info['features'] as $component => $features) { + if ($component == 'user_permission') { + foreach ($features as $key => $feature) { + // Export vocabulary permissions using the machine name, instead + // of vocabulary id. + _user_features_change_term_permission($feature); + $row->info['features'][$component][$key] = $feature; + } + } + } $data['feature'][$row->name] = $row; } $data['module'][$row->name] = $row; @@ -954,3 +966,24 @@ function features_hook_info() { ); return array_fill_keys($hooks, array('group' => 'features')); } +/** + * Change vocabularies permission, from vocab id to machine name and vice versa. + */ +function _user_features_change_term_permission(&$perm, $type = 'vid') { + // Export vocabulary permissions using the machine name, instead of vocabulary + // id. + if (strpos($perm, 'edit terms in ') !== FALSE || strpos($perm, 'delete terms in ') !== FALSE) { + preg_match("/(?<=\040)([^\s]+?)$/", trim($perm), $voc_id); + $vid = $voc_id[0]; + if (is_numeric($vid) && $type == 'vid') { + if (function_exists('taxonomy_vocabulary_load')) { + $voc = taxonomy_vocabulary_load($vid); + $perm = str_replace($vid, $voc->machine_name, $perm); + } + } + elseif ($type == 'machine_name') { + $voc = taxonomy_vocabulary_machine_name_load($vid); + $perm = str_replace($vid, $voc->vid, $perm); + } + } +} diff --git a/includes/features.user.inc b/includes/features.user.inc index 77f025b..33e9e82 100644 --- a/includes/features.user.inc +++ b/includes/features.user.inc @@ -29,8 +29,12 @@ function user_permission_features_export($data, &$export, $module_name = '') { // Ensure the modules that provide the given permissions are included as dependencies. $map = user_permission_get_modules(); foreach ($data as $perm) { - if (isset($map[$perm])) { - $perm_module = $map[$perm]; + $perm_name = $perm; + // Export vocabulary permissions using the machine name, instead of + // vocabulary id. + _user_features_change_term_permission($perm_name, 'machine_name'); + if (isset($map[$perm_name])) { + $perm_module = $map[$perm_name]; $export['dependencies'][$perm_module] = $perm_module; $export['features']['user_permission'][$perm] = $perm; } @@ -54,6 +58,9 @@ function user_permission_features_export_options() { foreach ($modules as $display_name => $module) { if ($permissions = module_invoke($module, 'permission')) { foreach ($permissions as $perm => $perm_item) { + // Export vocabulary permissions using the machine name, instead of + // vocabulary id. + _user_features_change_term_permission($perm); $options[$perm] = strip_tags("{$display_name}: {$perm_item['title']}"); } } @@ -78,7 +85,11 @@ function user_permission_features_export_render($module, $data) { foreach ($data as $perm_name) { $permission = array(); - $permission['name'] = $perm_name; + // Export vocabulary permissions using the machine name, instead of + // vocabulary id. + $perm = $perm_name; + _user_features_change_term_permission($perm_name, 'machine_name'); + $permission['name'] = $perm; if (!empty($permissions[$perm_name])) { sort($permissions[$perm_name]); $permission['roles'] = drupal_map_assoc($permissions[$perm_name]); @@ -89,9 +100,9 @@ function user_permission_features_export_render($module, $data) { if (isset($perm_modules[$perm_name])) { $permission['module'] = $perm_modules[$perm_name]; } - $perm_identifier = features_var_export($perm_name); + $perm_identifier = features_var_export($perm); $perm_export = features_var_export($permission, ' '); - $code[] = " // Exported permission: {$perm_name}."; + $code[] = " // Exported permission: {$perm_identifier}."; $code[] = " \$permissions[{$perm_identifier}] = {$perm_export};"; $code[] = ""; } @@ -126,6 +137,9 @@ function user_permission_features_rebuild($module) { $permissions_by_role = _user_features_get_permissions(FALSE); foreach ($defaults as $permission) { $perm = $permission['name']; + // Export vocabulary permissions using the machine name, instead of + // vocabulary id. + _user_features_change_term_permission($perm, 'machine_name'); foreach ($roles as $role) { if (in_array($role, $permission['roles'])) { $permissions_by_role[$role][$perm] = TRUE;