You are here

function party_permission in Party 8.2

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

Implements hook_permission().

File

./party.module, line 1033
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'),
    ),
    'create parties' => array(
      'title' => t('Create parties'),
    ),
    'edit parties' => array(
      'title' => t('Edit 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;
}