function media_wysiwyg_pre_render_text_format in D7 Media 7.2
Same name and namespace in other branches
- 7.4 modules/media_wysiwyg/media_wysiwyg.module \media_wysiwyg_pre_render_text_format()
- 7.3 modules/media_wysiwyg/media_wysiwyg.module \media_wysiwyg_pre_render_text_format()
Builds a map of media tags in the element.
Builds a map of the media tags in an element that are being rendered to their rendered HTML. The map is stored in JS, so we can transform them when the editor is being displayed.
1 string reference to 'media_wysiwyg_pre_render_text_format'
- media_wysiwyg_element_info_alter in modules/
media_wysiwyg/ media_wysiwyg.module - Implements hook_element_info_alter().
File
- modules/
media_wysiwyg/ media_wysiwyg.module, line 104 - Primarily Drupal hooks.
Code
function media_wysiwyg_pre_render_text_format($element) {
// filter_process_format() copies properties to the expanded 'value' child
// element.
if (!isset($element['format'])) {
return $element;
}
$field =& $element['value'];
$settings = array(
'field' => $field['#id'],
);
if (!isset($field['#value']) && $field['#value'] != '') {
return $element;
}
$tagmap = array();
foreach (array(
'value',
'summary',
) as $column) {
if (isset($element[$column]['#value'])) {
$tagmap += _media_wysiwyg_generate_tagMap($element[$column]['#value']);
}
}
if (!empty($tagmap)) {
$element['#attached']['js'][] = array(
'data' => array(
'tagmap' => $tagmap,
),
'type' => 'setting',
);
}
// Load the media browser library.
$element['#attached']['library'][] = array(
'media',
'media_browser',
);
$element['#attached']['library'][] = array(
'media',
'media_browser_settings',
);
// Add wysiwyg-specific settings.
$settings = array(
'wysiwyg_allowed_attributes' => media_wysiwyg_allowed_attributes(),
'img_alt_field' => 'field_file_image_alt_text',
'img_title_field' => 'field_file_image_title_text',
);
// The file_entity module lets you specify a string, possibly with tokens, for
// the alt and title attributes of images. We need the actual field names instead.
// If the variable only contains a token of the format [file:field_file_image_alt_text]
// then it's possible to extract it.
$alt_token = variable_get('file_entity_alt', '[file:field_file_image_alt_text]');
$title_token = variable_get('file_entity_title', '[file:field_file_image_title_text]');
$matches = array();
if (preg_match('/^\\[file:(field_[[:alnum:]_-]+)\\]$/', trim($alt_token), $matches)) {
$settings['img_alt_field'] = $matches[1];
}
if (preg_match('/^\\[file:(field_[[:alnum:]_-]+)\\]$/', trim($title_token), $matches)) {
$settings['img_title_field'] = $matches[1];
}
$element['#attached']['js'][] = array(
'data' => array(
'media' => $settings,
'mediaDoLinkText' => (bool) variable_get('media_wysiwyg_use_link_text_for_filename', 1),
),
'type' => 'setting',
);
// Add filter handling.
$element['#attached']['js'][] = drupal_get_path('module', 'media_wysiwyg') . '/js/media_wysiwyg.filter.js';
return $element;
}