You are here

function registration_tokens in Entity Registration 8

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

Implements hook_tokens().

File

./registration.module, line 1349

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, 'user')) {
      $entity = $wrapper->user
        ->value();
      $replacements += token_generate('user', $entity_tokens, array(
        'user' => $entity,
      ), $options);
    }
    return $replacements;
  }
}