You are here

function rabbit_hole_permission in Rabbit Hole 7.2

Same name and namespace in other branches
  1. 7 rabbit_hole.module \rabbit_hole_permission()

Implements hook_permission().

File

./rabbit_hole.module, line 23
Main module file for Rabbit Hole.

Code

function rabbit_hole_permission() {
  $permissions = array();

  // Load information from any module that implements hook_rabbit_hole().
  $modules = module_invoke_all('rabbit_hole');
  foreach ($modules as $module => $info) {

    // Get information about the entity.
    $entity_info = entity_get_info($info['entity type']);
    $entity_label = strtolower(isset($entity_info['plural label']) ? $entity_info['plural label'] : $entity_info['label']);

    // Add an administer permission.
    $permissions['administer ' . $module] = array(
      'title' => t('Administer Rabbit Hole settings for @entity_type', array(
        '@entity_type' => $entity_label,
      )),
    );

    // Add an PHP evaluation permission.
    $permissions['php redirect ' . $module] = array(
      'title' => t('Allow PHP redirect evaluation for @entity_type', array(
        '@entity_type' => $entity_label,
      )),
      'restrict access' => TRUE,
    );

    // Add a bypass permission.
    $permissions['bypass ' . $module] = array(
      'title' => t('Bypass Rabbit Hole action for @entity_type', array(
        '@entity_type' => $entity_label,
      )),
      'description' => t('Allows user to bypass the action that has been configured for @entity_type.', array(
        '@entity_type' => $entity_label,
      )),
      'restrict access' => TRUE,
    );
  }
  return $permissions;
}