You are here

function asset_get_default_formatter in Asset 6

Same name and namespace in other branches
  1. 5 asset.module \asset_get_default_formatter()

Get the default formatter for a given type and extension

7 calls to asset_get_default_formatter()
asset_admin_formatter_defaults in inc/asset.admin.inc
Menu callback for selection of default formatting options.
asset_img_preview in ./asset.module
Callback function to output an image for preview of an asset.
asset_lightbox in ./asset.module
Integrate asset with lightbox
asset_preview in ./asset.module
Build a preview of an asset based on module and format options. If no module and format info is given then the default teaser formatter is used.
asset_views_handler_field_asset in ./asset_views.inc

... See full list

File

inc/asset.routines.inc, line 52

Code

function asset_get_default_formatter($type, $ext, $teaser = FALSE) {
  $prefix = 'asset_default_formatter_' . ($teaser ? 'teaser_' : '');
  $vars = array(
    $prefix . $type . '_' . $ext,
    $prefix . $type . '_*',
    $prefix . '*_*',
  );
  foreach ($vars as $var) {
    if ($formatter = variable_get($var, false)) {
      break;
    }
  }

  // if var is not set, then cascade through possible formatters to find a suitable one
  if (!$formatter) {
    $formatters = asset_get_formatters();
    if (isset($formatters[$type][$ext][0])) {
      $format = $formatters[$type][$ext][0];
    }
    elseif (isset($formatters[$type]['*'][0])) {
      $format = $formatters[$type]['*'][0];
    }
    else {
      $format = $formatters['*']['*'][0];
    }
    $formatter = $format['module'] . ':' . $format['format'];
  }
  return $formatter;
}