You are here

function _user_features_change_term_permission in Features 7.2

Change vocabularies permission, from vocab id to machine name and vice versa.

The taxonomy module builds permission machine names from auto-increment taxonomy vocabulary vids, which is not useful when exporting to features.

On features export, these permission names are converted, replacing the vids with taxonomy machine names. On import, this is reversed.

Parameters

string $perm: A permission machine name from the real permissions system, or a modified permission machine name from a feature module. This will by modified (by reference), if it is one of:

  • 'edit terms in ' . $vid_or_name
  • 'delete terms in ' . $vid_or_name.

string $type: One of 'vid' or 'machine_name'. If 'vid', vocabulary ids will be replaced by machine names. If 'machine_name', vocabulary machine names will be replaced by vids.

See also

\taxonomy_permission()

5 calls to _user_features_change_term_permission()
features_get_info in ./features.module
Retrieves module info from the system table.
user_permission_features_export in includes/features.user.inc
Implements hook_features_export().
user_permission_features_export_options in includes/features.user.inc
Implements hook_features_export_options().
user_permission_features_export_render in includes/features.user.inc
Implements hook_features_export_render().
user_permission_features_rebuild in includes/features.user.inc
Implements hook_features_rebuild(). Iterate through default permissions and update the permissions map.

File

./features.module, line 1355
Main *.module file for the 'features' module.

Code

function _user_features_change_term_permission(&$perm, $type = 'vid') {
  if (!module_exists('taxonomy')) {
    return;
  }

  // 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("/(?<= )([^\\s]+?)\$/", trim($perm), $voc_id);
    $vid = $voc_id[0];
    if (is_numeric($vid) && $type == 'vid') {
      if (function_exists('taxonomy_vocabulary_load')) {
        if ($voc = taxonomy_vocabulary_load($vid)) {
          $perm = str_replace($vid, $voc->machine_name, $perm);
        }
      }
    }
    elseif ($type == 'machine_name') {
      if ($voc = taxonomy_vocabulary_machine_name_load($vid)) {
        $perm = str_replace($vid, $voc->vid, $perm);
      }
    }
  }
}