Issue #1939096 by chrisjlee, joelpittet, drupalmonkey | Cottser: Convert theme_feed_icon() to Twig.
parent
af711e6082
commit
bbf70b0c96
|
@ -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 @@ class AddFeedTest extends WebTestBase {
|
|||
* @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 &"'', 'theme_feed_icon() escapes reserved HTML characters.');
|
||||
$this->assertEqual($matches[1], 'Subscribe to &"'', 'feed_icon template escapes reserved HTML characters.');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
{#
|
||||
/**
|
||||
* @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>
|
Loading…
Reference in New Issue