You are here

function registration_access_people in Entity Registration 8

Same name and namespace in other branches
  1. 7 registration.module \registration_access_people()

Determine people types user may register for an entity.

This will take into account if a user already has a registration for a host entity.

Parameters

object $registration: A fully loaded registration object.

object $account: (optional) An user object, or omit for logged in user.

Return value

array Array keyed with people types, with descriptions.

2 calls to registration_access_people()
registration_access in ./registration.module
Access callback: Entity API for Registration entities.
registration_form in includes/registration.forms.inc
Form callback: create or edit a registration.

File

./registration.module, line 1456

Code

function registration_access_people(Registration $registration, $account = NULL) {
  $account = isset($account) ? $account : \Drupal::currentUser();
  $people = array();

  // Me
  $settings = registration_entity_settings($registration->entity_type, $registration->entity_id);
  $allow_multiple = !empty($settings['settings']['multiple_registrations']) && $settings['settings']['multiple_registrations'];
  if ($account->uid && ($account->uid === $registration->user_uid || (!registration_is_registered($registration, NULL, $account->uid) || $allow_multiple))) {
    $people[REGISTRATION_REGISTRANT_TYPE_ME] = t('Myself');
  }

  // Other users
  if ($account
    ->hasPermission("create {$registration->type} registration other users")) {
    $people[REGISTRATION_REGISTRANT_TYPE_USER] = t('Other account');
  }

  // Anonymous people
  if ($account
    ->hasPermission("create {$registration->type} registration other anonymous")) {
    $people[REGISTRATION_REGISTRANT_TYPE_ANON] = empty($account->uid) && $account->uid != 0 ? t('Myself') : t('Other person');
  }
  return $people;
}