You are here

function bat_entity_access_permissions in Booking and Availability Management Tools for Drupal 7

Same name and namespace in other branches
  1. 8 bat.module \bat_entity_access_permissions()

Return permission names for a given entity type.

3 calls to bat_entity_access_permissions()
bat_booking_permission in modules/bat_booking/bat_booking.module
Implements hook_permission().
bat_event_permission in modules/bat_event/bat_event.module
Implements hook_permission().
bat_unit_permission in modules/bat_unit/bat_unit.module
Implements hook_permission().

File

./bat.module, line 282
Provides basic underlying functionality and configuration options used by all BAT modules.

Code

function bat_entity_access_permissions($entity_type) {
  $entity_info = entity_get_info($entity_type);
  $labels = $entity_info['permission labels'];
  $permissions = array();

  // General 'bypass' permission.
  $permissions['bypass ' . $entity_type . ' entities access'] = array(
    'title' => t('Bypass access to @entity_type', array(
      '@entity_type' => $labels['plural'],
    )),
    'description' => t('Allows users to perform any action on @entity_type.', array(
      '@entity_type' => $labels['plural'],
    )),
    'restrict access' => TRUE,
  );

  // Generic create and edit permissions.
  $permissions['create ' . $entity_type . ' entities'] = array(
    'title' => t('Create @entity_type of any type', array(
      '@entity_type' => $labels['plural'],
    )),
  );
  if (!empty($entity_info['access arguments']['user key'])) {
    $permissions['view own ' . $entity_type . ' entities'] = array(
      'title' => t('View own @entity_type of any type', array(
        '@entity_type' => $labels['plural'],
      )),
    );
  }
  $permissions['view any ' . $entity_type . ' entity'] = array(
    'title' => t('View any @entity_type of any type', array(
      '@entity_type' => $labels['singular'],
    )),
    'restrict access' => TRUE,
  );
  if (!empty($entity_info['access arguments']['user key'])) {
    $permissions['update own ' . $entity_type . ' entities'] = array(
      'title' => t('Edit own @entity_type of any type', array(
        '@entity_type' => $labels['plural'],
      )),
    );
  }
  $permissions['update any ' . $entity_type . ' entity'] = array(
    'title' => t('Edit any @entity_type of any type', array(
      '@entity_type' => $labels['singular'],
    )),
    'restrict access' => TRUE,
  );
  if (!empty($entity_info['access arguments']['user key'])) {
    $permissions['delete own ' . $entity_type . ' entities'] = array(
      'title' => t('Delete own @entity_type of any type', array(
        '@entity_type' => $labels['plural'],
      )),
    );
  }
  $permissions['delete any ' . $entity_type . ' entity'] = array(
    'title' => t('Delete any @entity_type of any type', array(
      '@entity_type' => $labels['singular'],
    )),
    'restrict access' => TRUE,
  );

  // Per-bundle create and edit permissions.
  if (!empty($entity_info['entity keys']['bundle'])) {
    foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
      $permissions['create ' . $entity_type . ' entities of bundle ' . $bundle_name] = array(
        'title' => t('Create %bundle @entity_type', array(
          '@entity_type' => $labels['plural'],
          '%bundle' => $bundle_info['label'],
        )),
      );
      if (!empty($entity_info['access arguments']['user key'])) {
        $permissions['view own ' . $entity_type . ' entities of bundle ' . $bundle_name] = array(
          'title' => t('View own %bundle @entity_type', array(
            '@entity_type' => $labels['plural'],
            '%bundle' => $bundle_info['label'],
          )),
        );
      }
      $permissions['view any ' . $entity_type . ' entity of bundle ' . $bundle_name] = array(
        'title' => t('View any %bundle @entity_type', array(
          '@entity_type' => $labels['singular'],
          '%bundle' => $bundle_info['label'],
        )),
        'restrict access' => TRUE,
      );
      if (!empty($entity_info['access arguments']['user key'])) {
        $permissions['update own ' . $entity_type . ' entities of bundle ' . $bundle_name] = array(
          'title' => t('Edit own %bundle @entity_type', array(
            '@entity_type' => $labels['plural'],
            '%bundle' => $bundle_info['label'],
          )),
        );
      }
      $permissions['update any ' . $entity_type . ' entity of bundle ' . $bundle_name] = array(
        'title' => t('Edit any %bundle @entity_type', array(
          '@entity_type' => $labels['singular'],
          '%bundle' => $bundle_info['label'],
        )),
        'restrict access' => TRUE,
      );
      if (!empty($entity_info['access arguments']['user key'])) {
        $permissions['delete own ' . $entity_type . ' entities of bundle ' . $bundle_name] = array(
          'title' => t('Delete own %bundle @entity_type', array(
            '@entity_type' => $labels['plural'],
            '%bundle' => $bundle_info['label'],
          )),
        );
      }
      $permissions['delete any ' . $entity_type . ' entity of bundle ' . $bundle_name] = array(
        'title' => t('Delete any %bundle @entity_type', array(
          '@entity_type' => $labels['singular'],
          '%bundle' => $bundle_info['label'],
        )),
        'restrict access' => TRUE,
      );
    }
  }
  return $permissions;
}