You are here

function party_permission in Party 7

Same name and namespace in other branches
  1. 8.2 party.module \party_permission()

Implements hook_permission().

File

./party.module, line 851
Provides a generic CRM party entity.

Code

function party_permission() {
  $permissions = array(
    'administer crm settings' => array(
      'title' => t('Administer party settings'),
      'restrict access' => TRUE,
    ),
    'administer parties' => array(
      'title' => t('Administer parties'),
      'restrict access' => TRUE,
    ),
    'view parties' => array(
      'title' => t('View parties'),
    ),
    'view archived parties' => array(
      'title' => t('View archived parties'),
      'restrict access' => TRUE,
    ),
    'create parties' => array(
      'title' => t('Create parties'),
    ),
    'edit parties' => array(
      'title' => t('Edit parties'),
    ),
    'archive parties' => array(
      'title' => t('Archive parties'),
    ),
    'delete parties' => array(
      'title' => t('Delete parties'),
    ),
  );

  // Add permissions for each data set.
  foreach (party_get_data_set_info() as $data_set_name => $data_set) {

    // Build an array of default overrides.
    $overrides = array_fill_keys(array(
      'view',
      'attach',
      'edit',
      'detach',
    ), array());

    // Get the overrides from the data set if applicable.
    if (isset($data_set['permissions'])) {
      $overrides = array_merge_recursive($overrides, $data_set['permissions']);
    }
    $permissions['view party attached ' . $data_set_name] = $overrides['view'] + array(
      'title' => t('View party attached %name', array(
        '%name' => $data_set['label'],
      )),
    );
    $permissions['attach party ' . $data_set_name] = $overrides['attach'] + array(
      'title' => t('Add party attached %name', array(
        '%name' => $data_set['label'],
      )),
    );
    $permissions['edit party attached ' . $data_set_name] = $overrides['edit'] + array(
      'title' => t('Edit party attached %name', array(
        '%name' => $data_set['label'],
      )),
    );
    $permissions['detach party attached ' . $data_set_name] = $overrides['detach'] + array(
      'title' => t('Remove party attached %name', array(
        '%name' => $data_set['label'],
      )),
    );
  }
  return $permissions;
}