Commit e16b28eb authored by damienmckenna's avatar damienmckenna Committed by Damien McKenna
Browse files

Issue #3178419 by DamienMcKenna: Simplify the theme functions.

parent 39730461
......@@ -16,6 +16,7 @@ By DamienMcKenna: Unnecessary syntax change broke PHP 5.3 compatibility.
#3121196 by torotil, DamienMcKenna, calebtr: Support relative fragment or query
-only links.
#3208151 by DamienMcKenna: Coding standards cleanup.
#3178419 by DamienMcKenna: Simplify the theme functions.
Link 7.x-1.7, 2019-11-14
......
......@@ -1325,14 +1325,25 @@ function theme_link_formatter_link_host($vars) {
* Formats a link as an absolute URL.
*/
function theme_link_formatter_link_absolute($vars) {
$absolute = array('absolute' => TRUE);
return empty($vars['element']['url']) ? '' : url($vars['element']['url'], $absolute + $vars['element']);
// If no URL value is present there's no point in continuing.
if (empty(($vars['element']['url']))) {
return '';
}
// Hardcode the 'absolute' argument.
$vars['element']['absolute'] = TRUE;
return url($vars['element']['url'], $vars['element']);
}
/**
* Formats a link using the URL's domain for it's link text.
*/
function theme_link_formatter_link_domain($vars) {
// If no URL value is present there's no point in continuing.
if (empty(($vars['element']['url']))) {
return '';
}
$link_options = $vars['element'];
unset($link_options['title']);
unset($link_options['url']);
......@@ -1340,13 +1351,18 @@ function theme_link_formatter_link_domain($vars) {
if (!empty($vars['display']['settings']['strip_www'])) {
$domain = str_replace('www.', '', $domain);
}
return $vars['element']['url'] ? l($domain, $vars['element']['url'], $link_options) : '';
return l($domain, $vars['element']['url'], $link_options);
}
/**
* Formats a link without the http:// or https://.
*/
function theme_link_formatter_link_no_protocol($vars) {
// If no URL value is present there's no point in continuing.
if (empty(($vars['element']['url']))) {
return '';
}
$link_options = $vars['element'];
unset($link_options['title']);
unset($link_options['url']);
......@@ -1356,43 +1372,63 @@ function theme_link_formatter_link_no_protocol($vars) {
$replace = '';
$display_url = preg_replace($search, $replace, $vars['element']['url'], 1);
return $vars['element']['url'] ? l($display_url, $vars['element']['url'], $link_options) : '';
return l($display_url, $vars['element']['url'], $link_options);
}
/**
* Formats a link's title as plain text.
*/
function theme_link_formatter_link_title_plain($vars) {
return empty($vars['element']['title']) ? '' : check_plain(decode_entities($vars['element']['title']));
// If no title value is present there's no point in continuing.
if (empty(($vars['element']['title']))) {
return '';
}
return check_plain(decode_entities($vars['element']['title']));
}
/**
* Formats a link using an alternate display URL for its link text.
*/
function theme_link_formatter_link_url($vars) {
// If no URL value is present there's no point in continuing.
if (empty(($vars['element']['url']))) {
return '';
}
$link_options = $vars['element'];
if (isset($link_options['attributes']['class'])) {
$link_options['attributes']['class'] = array($link_options['attributes']['class']);
}
unset($link_options['title']);
unset($link_options['url']);
return $vars['element']['url'] ? l($vars['element']['display_url'], $vars['element']['url'], $link_options) : '';
return l($vars['element']['display_url'], $vars['element']['url'], $link_options);
}
/**
* Formats a link using "Link" as the link text.
*/
function theme_link_formatter_link_short($vars) {
// If no URL value is present there's no point in continuing.
if (empty(($vars['element']['url']))) {
return '';
}
$link_options = $vars['element'];
unset($link_options['title']);
unset($link_options['url']);
return $vars['element']['url'] ? l(t('Link'), $vars['element']['url'], $link_options) : '';
return l(t('Link'), $vars['element']['url'], $link_options);
}
/**
* Formats a link using the field's label as link text.
*/
function theme_link_formatter_link_label($vars) {
// If no URL value is present there's no point in continuing.
if (empty(($vars['element']['url']))) {
return '';
}
$link_options = $vars['element'];
unset($link_options['title']);
unset($link_options['url']);
......@@ -1401,7 +1437,7 @@ function theme_link_formatter_link_label($vars) {
$i18n_string_name = "field:{$vars['field']['field_name']}:{$vars['field']['bundle']}:label";
$label = i18n_string_translate($i18n_string_name, $label);
}
return $vars['element']['url'] ? l($label, $vars['element']['url'], $link_options) : '';
return l($label, $vars['element']['url'], $link_options);
}
/**
......
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