You are here

function registration_entity_access_registration_access in Entity Registration 7

Same name and namespace in other branches
  1. 8.2 modules/registration_entity_access/registration_entity_access.module \registration_entity_access_registration_access()
  2. 8 modules/registration_entity_access/registration_entity_access.module \registration_entity_access_registration_access()
  3. 7.2 modules/registration_entity_access/registration_entity_access.module \registration_entity_access_registration_access()

Implements hook_registration_access().

File

modules/registration_entity_access/registration_entity_access.module, line 27
Entity Registration per entity access control

Code

function registration_entity_access_registration_access($op, $registration, $account = NULL) {
  if ($op == 'create' && ($registration->entity_type && $registration->entity_id) && $account) {
    $settings = registration_entity_settings($registration->entity_type, $registration->entity_id);
    $entity_access_roles =& $settings['settings']['registration_entity_access_roles'];
    if (isset($entity_access_roles) && is_array($entity_access_roles)) {

      // if at least one role is configured, deny access to all roles except the enabled roles
      $allowed_roles = array_filter($entity_access_roles);
      if ($allowed_roles) {
        foreach ($allowed_roles as $role_id) {
          if (isset($account->roles[$role_id])) {
            return TRUE;
          }
        }
        return FALSE;
      }
    }
  }
}