You are here

function assets_render_by_tag in Asset 7

Renders asset with overridden optional fields.

3 calls to assets_render_by_tag()
assets_filter_replace_process in includes/asset.filters.inc
Filter callback for assets_filter_process.
assets_get_content in includes/asset.admin.inc
Page callback to get html for asset preview in wysiwyg.
asset_get_full_content in includes/asset.admin.inc
Page callback, return html of full asset.

File

includes/asset.filters.inc, line 10
Assets Input filters logic.

Code

function assets_render_by_tag($asset, $params_string, $in_editor = FALSE) {
  if (!empty($asset)) {
    $clone = clone $asset;
    $clone->in_editor = $in_editor;
    if (!$in_editor) {

      // Need double decode if ckeditor plugin HTML entities is enabled.
      $params_string = html_entity_decode(html_entity_decode($params_string, ENT_QUOTES, 'UTF-8'));
    }
    $options = json_decode('{' . $params_string . '}', TRUE);
    $view_mode = ASSET_DEFAULT_MODE;
    if (is_array($options)) {
      if (isset($options['mode'])) {
        $view_mode = $options['mode'];
      }
      if (isset($options['align'])) {
        $clone->align = $options['align'];
      }
      $values = array_diff_key($options, array(
        'mode' => 1,
        'align' => 1,
      ));
      _assets_set_field_value($clone, $values);
    }
    $clone->asset_options = $options;
    $clone->asset_source_string = $params_string;

    // As render works by reference we should pass variable instead of direct value.
    $clone_content = $clone
      ->view($view_mode);

    // trim() here is very important. Without trim,
    // if template started with space - dom structure of response will contains empty text node.
    return trim(render($clone_content));
  }
  return '';
}