You are here

function bat_unit_tokens in Booking and Availability Management Tools for Drupal 7

Implements hook_tokens().

File

modules/bat_unit/bat_unit.tokens.inc, line 39
Builds placeholder replacement tokens for unit-related data.

Code

function bat_unit_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  if ($type == 'bat_type' && !empty($data['bat_type'])) {
    $bat_type = $data['bat_type'];
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'author':
          $account = user_load($bat_type->uid);
          $name = format_username($account);
          $replacements[$original] = $sanitize ? check_plain($name) : $name;
          break;
      }
    }
    if ($author_tokens = token_find_with_prefix($tokens, 'author')) {
      $author = user_load($bat_type->uid);
      $replacements += token_generate('user', $author_tokens, array(
        'user' => $author,
      ), $options);
    }
  }
  if ($type == 'bat_unit' && !empty($data['bat_unit'])) {
    $bat_unit = $data['bat_unit'];
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'author':
          $account = user_load($bat_unit->uid);
          $name = format_username($account);
          $replacements[$original] = $sanitize ? check_plain($name) : $name;
          break;
      }
    }
    if ($author_tokens = token_find_with_prefix($tokens, 'author')) {
      $author = user_load($bat_unit->uid);
      $replacements += token_generate('user', $author_tokens, array(
        'user' => $author,
      ), $options);
    }
  }
  return $replacements;
}