function _media_wysiwyg_token_uuid_replace in D7 Media 7.3
Same name and namespace in other branches
- 7.4 modules/media_wysiwyg/includes/media_wysiwyg.uuid.inc \_media_wysiwyg_token_uuid_replace()
- 7.2 modules/media_wysiwyg/includes/media_wysiwyg.uuid.inc \_media_wysiwyg_token_uuid_replace()
Helper function to replace UUIDs with file IDs or vice versa.
Parameters
array $matches: An array of matches for media tokens, from a preg_replace_callback() callback function.
string $entity_uuid_function: Either 'entity_get_uuid_by_id' (to replace file IDs with UUIDs in the token) or 'entity_get_id_by_uuid' (to replace UUIDs with file IDs).
Return value
string A string representing the JSON-encoded token, with the appropriate replacement between file IDs and UUIDs.
2 calls to _media_wysiwyg_token_uuid_replace()
- media_wysiwyg_token_fid_to_uuid in modules/
media_wysiwyg/ includes/ media_wysiwyg.uuid.inc - Callback to replace file IDs with UUIDs in a media token.
- media_wysiwyg_token_uuid_to_fid in modules/
media_wysiwyg/ includes/ media_wysiwyg.uuid.inc - Callback to replace UUIDs with file IDs in a media token.
File
- modules/
media_wysiwyg/ includes/ media_wysiwyg.uuid.inc, line 77 - Functions related to adding UUID support to embedded media.
Code
function _media_wysiwyg_token_uuid_replace($matches, $entity_uuid_function) {
$tag = $matches[0];
$tag = str_replace(array(
'[[',
']]',
), '', $tag);
$tag_info = drupal_json_decode($tag);
if (isset($tag_info['fid'])) {
if ($new_ids = $entity_uuid_function('file', array(
$tag_info['fid'],
))) {
$new_id = reset($new_ids);
$tag_info['fid'] = $new_id;
}
}
return '[[' . drupal_json_encode($tag_info) . ']]';
}