Commit bbf70b0c authored by webchick's avatar webchick

Issue #1939096 by chrisjlee, joelpittet, drupalmonkey | Cottser: Convert theme_feed_icon() to Twig.

parent af711e60
......@@ -2295,19 +2295,28 @@ function theme_item_list($variables) {
}
/**
* Returns HTML for a feed icon.
* Prepares variables for feed icon templates.
*
* @param $variables
* Default template: feed-icon.html.twig.
*
* @param array $variables
* An associative array containing:
* - url: An internal system path or a fully qualified external URL of the
* feed.
* - title: A descriptive title of the feed.
*/
function theme_feed_icon($variables) {
function template_preprocess_feed_icon(&$variables) {
$text = t('Subscribe to !feed-title', array('!feed-title' => $variables['title']));
if ($image = theme('image', array('uri' => 'core/misc/feed.png', 'width' => 16, 'height' => 16, 'alt' => $text))) {
return l($image, $variables['url'], array('html' => TRUE, 'attributes' => array('class' => array('feed-icon'), 'title' => $text)));
}
$variables['icon'] = array(
'#theme' => 'image__feed_icon',
'#uri' => 'core/misc/feed.png',
'#width' => 16,
'#height' => 16,
'#alt' => $text,
);
$variables['attributes']['class'] = array('feed-icon');
// Stripping tags because that's what l() used to do.
$variables['attributes']['title'] = strip_tags($text);
}
/**
......@@ -3064,6 +3073,7 @@ function drupal_common_theme() {
),
'feed_icon' => array(
'variables' => array('url' => NULL, 'title' => NULL),
'template' => 'feed-icon',
),
'more_link' => array(
'variables' => array('url' => NULL, 'title' => NULL)
......
......@@ -96,11 +96,13 @@ function urlToRSSLinkPattern($url, $title = '') {
* @see http://drupal.org/node/1211668
*/
function testFeedIconEscaping() {
$variables = array();
$variables['url'] = 'node';
$variables['title'] = '<>&"\'';
$text = theme_feed_icon($variables);
$variables = array(
'#theme' => 'feed_icon',
'#url' => 'node',
'#title' => '<>&"\'',
);
$text = drupal_render($variables);
preg_match('/title="(.*?)"/', $text, $matches);
$this->assertEqual($matches[1], 'Subscribe to &amp;&quot;&#039;', 'theme_feed_icon() escapes reserved HTML characters.');
$this->assertEqual($matches[1], 'Subscribe to &amp;&quot;&#039;', 'feed_icon template escapes reserved HTML characters.');
}
}
{#
/**
* @file
* Default theme implementation for a feed icon.
*
* Available variables:
* - url: An internal system path or a fully qualified external URL of the feed.
* - icon: The rendered HTML (<img> tag) for the feed icon image.
* - attributes: Remaining HTML attributes for the feed link.
* - title: A descriptive title of the feed link.
* - class: HTML classes to be applied to the feed link.
*
* @see template_preprocess_feed_icon()
*
* @ingroup themeable
*/
#}
<a href="{{ url }}"{{ attributes }}>{{ icon }}</a>
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