You are here

function media_embed_formatted in Media WYSIWYG Embed 7

Returns formatted media item markup.

Parameters

object $file: File object.

string $formatter: Formatter name.

array $params: Additional parameters.

Return value

string Markup for the media item.

2 calls to media_embed_formatted()
media_embed_apitoken_media_embed in ./media_embed.module
Handler for the "media-embed" API token.
media_embed_formatted_wysiwyg in ./media_embed.module
Returns formatted media item markup for WYSIWYG.

File

./media_embed.module, line 273

Code

function media_embed_formatted($file, $formatter, $params) {
  $element = array();
  if (empty($params['processed'])) {
    $params = media_embed_params($params);
  }
  $formatters = media_embed_formatter_options($file, $params['settings']);
  if (isset($formatters[$formatter])) {
    $formatter_info = file_info_formatter_types($formatter);
    $settings = media_embed_formatter_settings($formatter_info, $params['settings']);
    $display = array(
      'type' => $formatter,
      'settings' => $settings,
    );
    $callback = isset($formatter_info['view callback']) ? $formatter_info['view callback'] : '';
    if (function_exists($callback)) {
      $langcode = $GLOBALS['language_content']->language;
      $element = $callback($file, $display, $langcode);
      if ($params['wrapper']) {
        $wrapper = $params['wrapper'];
        $attributes = array(
          'class' => array(
            'media-embed',
          ),
        );
        $wrapper['class'] && ($attributes['class'][] = $wrapper['class']);
        $wrapper['id'] && ($attributes['id'] = $wrapper['id']);
        $element = array(
          '#theme_wrappers' => array(
            'container',
          ),
          '#attributes' => $attributes,
          $element,
        );
      }
      if (empty($file->override['wysiwyg'])) {
        $_file = clone $file;
        drupal_alter('media_embed_formatted', $element, $display, $_file);
      }
    }
  }
  return drupal_render($element);
}