You are here

function registration_tokens in Entity Registration 7.2

Same name and namespace in other branches
  1. 8.2 registration.module \registration_tokens()
  2. 8 registration.module \registration_tokens()
  3. 7 registration.module \registration_tokens()

Implements hook_tokens().

File

./registration.module, line 1430

Code

function registration_tokens($type, $tokens, array $data = array(), array $options = array()) {
  if ($type == 'registration' && !empty($data['registration'])) {
    $registration = $data['registration'];
    $wrapper = entity_metadata_wrapper('registration', $data['registration']);
    $replacements = array();
    if ($entity_tokens = token_find_with_prefix($tokens, 'entity')) {
      $entity = $wrapper->entity
        ->value();
      $replacements += token_generate($registration->entity_type, $entity_tokens, array(
        $registration->entity_type => $entity,
      ), $options);
    }
    if ($entity_tokens = token_find_with_prefix($tokens, 'registrant')) {
      $registration_type = registration_get_types($wrapper
        ->type());
      $registrant = $wrapper->registrant
        ->value();
      $replacements += token_generate($registration_type->registrant_entity_type, $entity_tokens, array(
        $registration_type->registrant_entity_type => $registrant,
      ), $options);
    }
    return $replacements;
  }
}