Commit 71cddd95 authored by joelpittet's avatar joelpittet Committed by John Fiala
Browse files

Issue #2055111 by joelpittet, mikeytown2: skip over re-loading entities for...

Issue #2055111 by joelpittet, mikeytown2: skip over re-loading entities for tokens in link field attributes unless there's a token to process.
parent 2e82084e
......@@ -474,16 +474,18 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
$entity_type == 'taxonomy_term' || $entity_type == 'taxonomy_vocabulary' ? str_replace('taxonomy_', '', $entity_type) : $entity_type
);
if (isset($instance['settings']['enable_tokens']) && $instance['settings']['enable_tokens']) {
global $user;
// Load the entity if necessary for entities in views.
if (isset($entity->{$property_id})) {
$entity_loaded = entity_load($entity_type, array($entity->{$property_id}));
$entity_loaded = array_pop($entity_loaded);
}
else {
$entity_loaded = $entity;
$text_tokens = token_scan($item['url']);
if (!empty($text_tokens)) {
// Load the entity if necessary for entities in views.
if (isset($entity->{$property_id})) {
$entity_loaded = entity_load($entity_type, array($entity->{$property_id}));
$entity_loaded = array_pop($entity_loaded);
}
else {
$entity_loaded = $entity;
}
$item['url'] = token_replace($item['url'], array($entity_token_type => $entity_loaded));
}
$item['url'] = token_replace($item['url'], array($entity_token_type => $entity_loaded));
}
$type = link_validate_url($item['url']);
......@@ -541,15 +543,18 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
// Replace title tokens.
if ($title && ($instance['settings']['title'] == 'value' || $instance['settings']['enable_tokens'])) {
// Load the entity if necessary for entities in views.
if (isset($entity->{$property_id})) {
$entity_loaded = entity_load($entity_type, array($entity->{$property_id}));
$entity_loaded = array_pop($entity_loaded);
}
else {
$entity_loaded = $entity;
$text_tokens = token_scan($title);
if (!empty($text_tokens)) {
// Load the entity if necessary for entities in views.
if (isset($entity->{$property_id})) {
$entity_loaded = entity_load($entity_type, array($entity->{$property_id}));
$entity_loaded = array_pop($entity_loaded);
}
else {
$entity_loaded = $entity;
}
$title = token_replace($title, array($entity_token_type => $entity_loaded));
}
$title = token_replace($title, array($entity_token_type => $entity_loaded));
$title = filter_xss($title, array('b', 'br', 'code', 'em', 'i', 'img', 'span', 'strong', 'sub', 'sup', 'tt', 'u'));
$item['html'] = TRUE;
}
......@@ -599,15 +604,18 @@ function _link_sanitize(&$item, $delta, &$field, $instance, &$entity) {
// Handle "title" link attribute.
if (!empty($item['attributes']['title']) && module_exists('token')) {
// Load the entity (necessary for entities in views).
if (isset($entity->{$property_id})) {
$entity_loaded = entity_load($entity_type, array($entity->{$property_id}));
$entity_loaded = array_pop($entity_loaded);
}
else {
$entity_loaded = $entity;
$text_tokens = token_scan($item['attributes']['title']);
if (!empty($text_tokens)) {
// Load the entity (necessary for entities in views).
if (isset($entity->{$property_id})) {
$entity_loaded = entity_load($entity_type, array($entity->{$property_id}));
$entity_loaded = array_pop($entity_loaded);
}
else {
$entity_loaded = $entity;
}
$item['attributes']['title'] = token_replace($item['attributes']['title'], array($entity_token_type => $entity_loaded));
}
$item['attributes']['title'] = token_replace($item['attributes']['title'], array($entity_token_type => $entity_loaded));
$item['attributes']['title'] = filter_xss($item['attributes']['title'], array('b', 'br', 'code', 'em', 'i', 'img', 'span', 'strong', 'sub', 'sup', 'tt', 'u'));
}
// Handle attribute classes.
......@@ -1142,7 +1150,7 @@ function link_views_api() {
/**
* Forms a valid URL if possible from an entered address.
*
*
* Trims whitespace and automatically adds an http:// to addresses without a
* protocol specified
*
......@@ -1173,7 +1181,7 @@ function link_cleanup_url($url, $protocol = 'http') {
/**
* Validates a URL.
*
*
* Accepts all URLs following RFC 1738 standard for URL formation and all e-mail
* addresses following the RFC 2368 standard for mailto address formation.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment