function uuid_link_form_post_render in UUID Link 7
Post render callback. Load javascript files and set module settings.
1 string reference to 'uuid_link_form_post_render'
- uuid_link_element_info_alter in ./
uuid_link.module - Implements hook_element_info_alter().
File
- ./
uuid_link.module, line 70 - Provides a filter and UI for adding links to entities that are not affected by changes in URL alias.
Code
function uuid_link_form_post_render($content, $element) {
static $added;
if (empty($added) && ($js = drupal_add_js()) && isset($js['settings']['data'])) {
$settings = call_user_func_array('array_merge_recursive', $js['settings']['data']);
if (isset($settings['ckeditor']) || isset($settings['wysiwyg']['configs']['ckeditor'])) {
// Pre-load all UUID titles.
preg_match_all('/\\[uuid-link:(.*?)\\]/', $content, $matches);
$tokens = array_unique($matches[1]);
$uuids = array();
foreach ($tokens as $token) {
list($entity_type, $uuid) = explode(':', $token);
$uuids[$entity_type][$uuid] = $uuid;
}
foreach (array_keys($uuids) as $entity_type) {
$entities = entity_uuid_load($entity_type, $uuids[$entity_type]);
foreach ($entities as $entity_id => $entity) {
// If content is language specific show language code.
if (!empty($entity->language) && $entity->language != LANGUAGE_NONE) {
$uuids[$entity_type][$entity->uuid] = t('[@language] @label', array(
'@language' => $entity->language,
'@label' => entity_label($type, $entity),
));
}
else {
$uuids[$entity_type][$entity->uuid] = check_plain(entity_label($entity_type, $entity));
}
}
}
$added = TRUE;
drupal_add_js('misc/autocomplete.js');
$settings = array(
'autocomplete_path' => url('uuid-link/autocomplete'),
'type_name' => uuid_link_get_link_type_name(),
'uuids' => $uuids,
);
drupal_add_js(array(
'uuid_link' => $settings,
), 'setting');
}
}
return $content;
}