You are here

function _media_generate_tagMap in D7 Media 7

Generates an array of [inline tags] => <html> to be used in filter replacement and to add the mapping to JS.

Parameters

The String containing text and html markup of textarea:

Return value

An associative array with tag code as key and html markup as the value.

See also

media_process_form()

media_token_to_markup()

1 call to _media_generate_tagMap()
media_pre_render_text_format in includes/media.filter.inc
Builds a map of media tags in the element being rendered to their rendered HTML.

File

includes/media.filter.inc, line 444
Functions related to the WYSIWYG editor and the media input filter.

Code

function _media_generate_tagMap($text) {

  // Making $tagmap static as this function is called many times and
  // adds duplicate markup for each tag code in Drupal.settings JS,
  // so in media_process_form it adds something like tagCode:<markup>,
  // <markup> and when we replace in attach see two duplicate images
  // for one tagCode. Making static would make function remember value
  // between function calls. Since media_process_form is multiple times
  // with same form, this function is also called multiple times.
  static $tagmap = array();
  preg_match_all("/\\[\\[.*?\\]\\]/s", $text, $matches, PREG_SET_ORDER);
  foreach ($matches as $match) {

    // We see if tagContent is already in $tagMap, if not we add it
    // to $tagmap.  If we return an empty array, we break embeddings of the same
    // media multiple times.
    if (empty($tagmap[$match[0]])) {

      // @TODO: Total HACK, but better than nothing.
      // We should find a better way of cleaning this up.
      if ($markup_for_media = media_token_to_markup($match, TRUE)) {
        $tagmap[$match[0]] = $markup_for_media;
      }
      else {
        $missing = file_create_url(drupal_get_path('module', 'media') . '/images/icons/default/image-x-generic.png');
        $tagmap[$match[0]] = '<div><img src="' . $missing . '" width="100px" height="100px"/></div>';
      }
    }
  }
  return $tagmap;
}