diff --git a/core/includes/theme.inc b/core/includes/theme.inc index b5a94edb4ae8e432a87fcf9633475b5ff7ccb737..93546dc970ef76211237872900a11ae56dc8e6c3 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1692,12 +1692,15 @@ function theme_status_messages($variables) { * * @param $variables * An associative array containing the keys 'text', 'path', and 'options'. - * See the l() function for information about these variables. + * See the l() function for information about these variables. However, unlike + * 'text' in l() both render arrays and strings are supported here. * * @see l() */ -function theme_link(&$variables) { - return l($variables['text'], $variables['path'], $variables['options']); +function theme_link($variables) { + // A link's text can be a string or a renderable array. + $rendered_text = is_array($variables['text']) ? drupal_render($variables['text']) : $variables['text']; + return l($rendered_text, $variables['path'], $variables['options']); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php index dedddb0f862eaba86160b2216e1c25a37b9299a1..8a9f5f4aabdcd248bf580401ace307c28f19847a 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php @@ -134,6 +134,32 @@ function testLinkCustomClass() { } /** + * Tests that theme('link') supports renderable arrays provided as 'text'. + */ + function testLinkNestedRenderArrays() { + // Build a link with l() for reference. + $l = l('foo', 'http://drupal.org'); + + // Test a themed link with plain text 'text'. + $theme_link_plain_array = array( + '#theme' => 'link', + '#text' => 'foo', + '#path' => 'http://drupal.org', + ); + $theme_link_plain = drupal_render($theme_link_plain_array); + $this->assertEqual($theme_link_plain, $l); + + // Build a themed link with renderable 'text'. + $theme_link_nested_array = array( + '#theme' => 'link', + '#text' => array('#markup' => 'foo'), + '#path' => 'http://drupal.org', + ); + $theme_link_nested = drupal_render($theme_link_nested_array); + $this->assertEqual($theme_link_nested, $l); + } + + /** * Checks for class existence in link. * * @param $link