You are here

mobile_codes.formatter.inc in Mobile Codes 5

Same filename and directory in other branches
  1. 6 mobile_codes.formatter.inc

File

mobile_codes.formatter.inc
View source
<?php

/**
 * @file
 */
function mobile_codes_field_formatter_info() {
  $formatters = array();
  include_once drupal_get_path('module', 'mobile_codes') . '/mobile_codes.admin.inc';
  foreach (mobile_codes_get_presets() as $preset) {
    $formatters['mobile_codes_' . $preset->name . '_default'] = array(
      'label' => t('Mobile code: @preset image', array(
        '@preset' => $preset->name,
      )),
      'field types' => array(
        'text',
      ),
    );
    $formatters['mobile_codes_' . $preset->name . '_path'] = array(
      'label' => t('Mobile code: @preset file path', array(
        '@preset' => $preset->name,
      )),
      'field types' => array(
        'text',
      ),
    );
  }
  return $formatters;
}
function mobile_codes_field_formatter($field, $item, $formatter, $node) {
  preg_match('/^mobile_codes_(.*)_(.*)$/', $formatter, $matches);
  $arguments = array(
    'data' => 'text',
    'preset' => $matches[1],
  );
  switch ($matches[2]) {
    case 'path':
      $output = mobile_codes_generate($item['value'], $arguments);
      break;
    default:
      $output = theme('mobilecode', $item['value'], $arguments);
      break;
  }
  return $output;
}