You are here

function text_mobile_codes_tokens_alter_alter in Mobile Codes 7.2

Implements hook_mobile_codes_tokens_alter_alter() on behalf of text.module.

File

includes/text.inc, line 34
Text module integration.

Code

function text_mobile_codes_tokens_alter_alter(&$replacements, $context) {
  $presets = mobile_codes_presets_load_all();
  if ($context['type'] == 'text-field-value' && !empty($context['data']['item'])) {
    foreach ($context['tokens'] as $name => $original) {
      switch ($name) {
        case 'mobile-codes':
          $replacements[$original] = theme('mobilecode', array(
            'data' => $context['data']['item']['value'],
            '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' => $context['data']['item']['value'],
      ));
    }
  }
}