You are here

function asset_views_handler_field_asset in Asset 6

Same name in this branch
  1. 6 asset_views.inc \asset_views_handler_field_asset()
  2. 6 inc/asset_views.inc \asset_views_handler_field_asset()
  3. 6 modules/asset_views.inc \asset_views_handler_field_asset()
Same name and namespace in other branches
  1. 5.2 modules/asset_views.inc \asset_views_handler_field_asset()
  2. 5 asset_views.inc \asset_views_handler_field_asset()
6 calls to asset_views_handler_field_asset()
asset_views_handler_field_asset_link in ./asset_views.inc
asset_views_handler_field_asset_link in inc/asset_views.inc
asset_views_handler_field_asset_link in modules/asset_views.inc
asset_views_handler_field_asset_node_link in ./asset_views.inc
asset_views_handler_field_asset_node_link in inc/asset_views.inc

... See full list

File

modules/asset_views.inc, line 115

Code

function asset_views_handler_field_asset($fieldinfo, $fielddata, $value, $data, $link = false) {
  static $formatters;
  if (!$formatters) {
    $formatters = asset_get_formatters();
  }
  $asset = asset_load($value);
  switch ($fielddata['options']) {
    case 'full':
      list($module, $format) = explode(':', asset_get_default_formatter($asset->type, $asset->extension, false));
      break;
    case 'teaser':
      list($module, $format) = explode(':', asset_get_default_formatter($asset->type, $asset->extension, true));
      break;
    default:
      list($module, $format) = explode(':', $fielddata['options']);
      $found = false;
      foreach ((array) $formatters[$asset->type][$asset->extension] as $formatter) {
        if ($formatter['module'] == $module && $formatter['format'] == $format) {
          $found = true;
          break;
        }
      }
      foreach ((array) $formatters[$asset->type]['*'] as $formatter) {
        if ($formatter['module'] == $module && $formatter['format'] == $format) {
          $found = true;
          break;
        }
      }
      foreach ((array) $formatters['*']['*'] as $formatter) {
        if ($formatter['module'] == $module && $formatter['format'] == $format) {
          $found = true;
          break;
        }
      }
      if (!$found) {
        $module = 'asset';
        $format = 'link';
      }
      break;
  }
  if ($link) {
    if ($format == 'link') {
      $html = $asset->title ? $asset->title : $asset->filename;
    }
    else {
      $html = module_invoke($module, 'asset_formatter', 'render', $asset, array(
        'format' => $format,
      ));
    }
    return l($html, $link, array(), null, null, false, true);
  }
  else {
    return module_invoke($module, 'asset_formatter', 'render', $asset, array(
      'format' => $format,
    ));
  }
}