You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$text with fid in each media token replaced by the local value.
*/
function baseline_content_media_replace_fids($text) {
if (module_exists('media_wysiwyg')) {
$text = preg_replace_callback(MEDIA_WYSIWYG_TOKEN_REGEX, 'baseline_content_media_token_filter', $text);
}
return $text;
}
/**
Implements hook_filter_info_alter().
*
Replace fids before filtering the output.
*/
function baseline_content_filter_info_alter(&$filters) {
$filters['media_filter']['prepare callback'] = 'baseline_content_media_replace_fids';
}
/**
Implements hook_element_info_alter().
*
Replace fids before loading the input in a textarea.
*/
function baseline_content_element_info_alter(&$types) {
// Replace fid's by the fid's from the current environment in text fields.
if (!isset($types['text_format']['#pre_render'])) {
$types['text_format']['#pre_render'] = array();
}
array_unshift($types['text_format']['#pre_render'], 'baseline_content_pre_render_text_format');
}
/**
Replaces the fid of media tokens by the ones in the current environment.
*/
function baseline_content_pre_render_text_format($element) {
// filter_process_format() copies properties to the expanded 'value' child
// element.
if (!isset($element['format'])) {
return $element;
}
When not using the media module, you are unable to create text formats.
Relevant code:
[code]
}
/**
*
*
*/
function baseline_content_media_replace_fids($text) {
if (module_exists('media_wysiwyg')) {
$text = preg_replace_callback(MEDIA_WYSIWYG_TOKEN_REGEX, 'baseline_content_media_token_filter', $text);
}
return $text;
}
/**
*
*/
function baseline_content_filter_info_alter(&$filters) {
$filters['media_filter']['prepare callback'] = 'baseline_content_media_replace_fids';
}
/**
*
*/
function baseline_content_element_info_alter(&$types) {
// Replace fid's by the fid's from the current environment in text fields.
if (!isset($types['text_format']['#pre_render'])) {
$types['text_format']['#pre_render'] = array();
}
array_unshift($types['text_format']['#pre_render'], 'baseline_content_pre_render_text_format');
}
/**
Replaces the fid of media tokens by the ones in the current environment.
*/
function baseline_content_pre_render_text_format($element) {
// filter_process_format() copies properties to the expanded 'value' child
// element.
if (!isset($element['format'])) {
return $element;
}
$element['value']['#value'] = baseline_content_media_replace_fids($element['value']['#value']);
return $element;
}
/**
*
@see feature_excentis_import_media_replace_fid()
@see media_token_to_markup()
@see feature_excentis_import_media_filter()
*/
function baseline_content_media_token_filter($match) {
$settings = array();
$tag = $match[0];
$tag = urldecode($tag);
$tag = str_replace("[[", "", $tag);
$tag = str_replace("]]", "", $tag);
try {
if (!is_string($tag)) {
throw new Exception('Unable to find matching tag');
}
$tag_info = drupal_json_decode($tag);
// Replace the fid if there's an import_source.
if (isset($tag_info['import_source']) && isset($tag_info['migration'])) {
$fid = baseline_content_get_fid($tag_info['import_source'], $tag_info['migration']);
if ($fid && $fid != $tag_info['fid']) {
$match[0] = str_replace('"fid":"' . $tag_info['fid'] . '"', '"fid":"' . $fid . '"', $match[0]);
$match[0] = str_replace('%22fid%22:%22' . $tag_info['fid'] . '%22', '%22fid%22:%22' . $fid . '%22', $match[0]);
}
}
}
catch (Exception $e) {
watchdog('media', 'Unable to render media from %tag. Error: %error', array('%tag' => $tag, '%error' => $e->getMessage()));
return '';
}
return $match[0];
}
/**
*
[code]
The text was updated successfully, but these errors were encountered: