From bbf70b0c961969456ad94ef082cc58999ceac9bf Mon Sep 17 00:00:00 2001 From: webchick Date: Fri, 30 Aug 2013 23:41:29 -0700 Subject: [PATCH] Issue #1939096 by chrisjlee, joelpittet, drupalmonkey | Cottser: Convert theme_feed_icon() to Twig. --- core/includes/theme.inc | 22 ++++++++++++++----- .../system/Tests/Common/AddFeedTest.php | 12 +++++----- .../system/templates/feed-icon.html.twig | 18 +++++++++++++++ 3 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 core/modules/system/templates/feed-icon.html.twig diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 330c448af1f..87b3b18001e 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -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) diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/AddFeedTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/AddFeedTest.php index e23525ed89e..3fbb36518c7 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/AddFeedTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/AddFeedTest.php @@ -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.'); } } diff --git a/core/modules/system/templates/feed-icon.html.twig b/core/modules/system/templates/feed-icon.html.twig new file mode 100644 index 00000000000..a9e0f03c18a --- /dev/null +++ b/core/modules/system/templates/feed-icon.html.twig @@ -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 ( 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 + */ +#} +{{ icon }}