You are here

function field_permissions_list_field_permissions in Field Permissions 7

Returns field permissions in a format suitable for use in hook_permission().

Parameters

array $field: The field to return permissions for.

mixed $label: (optional) The human readable name of the field to use when constructing permission names; for example, this might be the label of one of the corresponding field instances. If not provided, an appropriate label will be automatically derived from all the field's instances.

Return value

array An array of permission information, suitable for use in hook_permission().

4 calls to field_permissions_list_field_permissions()
field_permissions_features_pipe_field_base_alter in ./field_permissions.module
Implements hook_features_pipe_COMPONENT_alter().
field_permissions_overview in ./field_permissions.admin.inc
Menu callback; Field permissions overview.
field_permissions_permissions_matrix in ./field_permissions.admin.inc
Returns a field permissions matrix that can be inserted into a form.
_field_permissions_permission in ./field_permissions.admin.inc
Implements hook_permission().

File

./field_permissions.admin.inc, line 59
Administrative interface for the Field Permissions module.

Code

function field_permissions_list_field_permissions($field, $label = NULL) {
  if (!isset($label)) {
    $label = $field['field_name'];
  }
  $instances = array();
  $description = '';
  foreach ($field['bundles'] as $entity_type => $bundles) {
    foreach ($bundles as $bundle_name) {
      $instance = field_info_instance($entity_type, $field['field_name'], $bundle_name);
      $entity = entity_get_info($entity_type);
      if (!isset($entity['bundles'][$bundle_name])) {
        continue;
      }
      $instance_desc_tokens = array(
        $entity['label'],
        $entity['bundles'][$bundle_name]['label'],
        $instance['label'],
      );
      $instances[] = '"' . implode(':', $instance_desc_tokens) . '"';
    }
    $description = t('This field appears as: %instances.', array(
      '%instances' => implode(', ', $instances),
    ));
  }
  $permissions = array();
  foreach (field_permissions_list($label) as $permission_type => $permission_info) {
    $permission = $permission_type . ' ' . $field['field_name'];
    $permissions[$permission] = array(
      'title' => $permission_info['title'],
      'description' => $description,
    );
  }
  return $permissions;
}