You are here

function _asset_get_tag in Asset 7

Page callback, return html of asset by wysiwyg view mode.

1 string reference to '_asset_get_tag'
asset_menu in ./asset.module
Implements hook_menu().

File

includes/asset.admin.inc, line 572
Asset admin page callbacks.

Code

function _asset_get_tag($tag_id, $view_mode = NULL, $align = NULL) {
  $tags = !empty($tag_id) ? explode(':', $tag_id) : array();
  $asset = !empty($tags[0]) ? asset_load($tags[0]) : NULL;
  if ($asset) {
    if (empty($view_mode) || $view_mode == 'default') {
      $view_modes = variable_get('assets_default_wysiwyg_modes', array());
      if (!empty($view_modes[$asset->type])) {
        $view_mode = $view_modes[$asset->type];
      }
      else {
        $view_mode = ASSET_DEFAULT_MODE;
      }
    }
    $asset->in_editor = TRUE;
    $placeholder = assets_build_placeholder($asset, array(
      'mode' => $view_mode,
      'align' => $align,
    ));
    $placeholder = str_replace("\r\n", '\\n', $placeholder);
    $asset_content = $asset
      ->view($view_mode);
    $output = render($asset_content);

    // trim() here is very important. Without trim,
    // if template started with space - dom structure of response will contains empty text node.
    return array(
      'tag' => $placeholder,
      'content' => trim($output),
    );
  }
}