You are here

function eck_permission in Entity Construction Kit (ECK) 7.2

Same name and namespace in other branches
  1. 7.3 eck.permissions.inc \eck_permission()
  2. 7 eck.module \eck_permission()

Implements hook_permission().

A pretty through set of permission you can set permissiona at each level: entity_type, bundle, entity and for each action of the CRUD

File

./eck.module, line 480

Code

function eck_permission() {
  module_load_include('inc', 'eck', 'eck.entity_type');
  module_load_include('inc', 'eck', 'eck.bundle');
  $perms = array(
    // Entity Type permissions.
    'eck administer entity types' => array(
      'title' => t('Administer Entity Types'),
      'restrict access' => TRUE,
      'description' => t('Grants the ability to administer(add/edit/delete/view) any ECK Entity Type.'),
    ),
    'eck add entity types' => array(
      'title' => t('Add Entity Types'),
      'restrict access' => TRUE,
    ),
    'eck edit entity types' => array(
      'title' => t('Edit Entity Types'),
      'restrict access' => TRUE,
    ),
    'eck delete entity types' => array(
      'title' => t('Delete Entity Types'),
      'restrict access' => TRUE,
    ),
    'eck list entity types' => array(
      'title' => t('View Entity Type List'),
    ),
    // Bundle Permissions.
    'eck administer bundles' => array(
      'title' => t('Administer Bundles'),
      'restrict access' => TRUE,
      'description' => t('Grants the ability to administer(add/edit/delete/list) any ECK Bundle.'),
    ),
    'eck add bundles' => array(
      'title' => t('Add Bundles'),
      'restrict access' => TRUE,
      'description' => t('Grants the ability to add new bundles to any Entity type.'),
    ),
    'eck edit bundles' => array(
      'title' => t('Edit Bundles'),
      'restrict access' => TRUE,
    ),
    'eck delete bundles' => array(
      'title' => t('Delete Bundles'),
      'restrict access' => TRUE,
    ),
    'eck list bundles' => array(
      'title' => t('View Bundle Lists'),
    ),
    // Entitiy Permissions.
    'eck administer entities' => array(
      'title' => t('Administer Entities'),
      'restrict access' => TRUE,
    ),
    'eck add entities' => array(
      'title' => t('Add Entities'),
      'restrict access' => TRUE,
      'description' => t('Grants the ability to add new entities of any Entity type.'),
    ),
    'eck edit entities' => array(
      'title' => t('Edit Any Entity'),
      'restrict access' => TRUE,
    ),
    'eck delete entities' => array(
      'title' => t('Delete Any Entity'),
      'restrict access' => TRUE,
    ),
    'eck view entities' => array(
      'title' => t('View Any Entity'),
    ),
    'eck list entities' => array(
      'title' => t('View Entity Lists'),
      'description' => t('Grants the ability to view the list of entities displayed on any bundle page.'),
    ),
  );
  $perms_info = array(
    'eck administer' => 'Administer',
    'eck add' => "Add",
    'eck edit' => 'Edit',
    'eck delete' => 'Delete',
    'eck list' => 'View List of',
    'eck view' => 'View',
  );
  foreach (EntityType::loadAll() as $entity_type) {
    $perms["manage {$entity_type->name} properties"] = array(
      'title' => "Manage {$entity_type->label} Properties",
    );
    foreach ($perms_info as $op => $op_label) {
      $perms["{$op} {$entity_type->name} bundles"] = array(
        'title' => "{$op_label} {$entity_type->label} Bundles",
      );
    }
    foreach (Bundle::loadByEntityType($entity_type) as $bundle) {
      $entity_perm_info = $perms_info + array(
        'eck view' => "View",
      );
      foreach ($entity_perm_info as $op => $op_label) {
        $perm_name = "{$op} {$entity_type->name} {$bundle->name} entities";
        $perms[$perm_name] = array(
          'title' => "{$op_label} {$entity_type->label} {$bundle->label} Entities",
        );
      }
    }
  }
  return $perms;
}