You are here

function vcard_mobile_codes_tokens_alter_alter in Mobile Codes 7.2

Implements hook_mobile_codes_tokens_alter_alter() on behalf of vcard.module.

File

includes/vcard.inc, line 40
vCard module integration

Code

function vcard_mobile_codes_tokens_alter_alter(&$replacements, $context) {
  $presets = mobile_codes_presets_load_all();
  if ($context['type'] == 'user' && !empty($context['data']['user'])) {
    $vcard = vcard_get($context['data']['user']);
    $vcard_text = $vcard
      ->fetch();
    foreach ($context['tokens'] as $name => $original) {
      switch ($name) {
        case 'mobile-codes':
          $replacements[$original] = theme('mobilecode', array(
            'data' => $vcard_text,
            'attributes' => array(
              '#preset' => key($presets),
            ),
          ));
          break;
      }
    }
    if ($mobile_codes_tokens = token_find_with_prefix($context['tokens'], 'mobile-codes')) {
      $replacements += token_generate('mobile-codes', $mobile_codes_tokens, array(
        'mobile-codes-data' => $vcard_text,
      ));
    }
  }
}