diff --git a/core/includes/common.inc b/core/includes/common.inc index 84cfa94540e..e4c9505b12b 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1631,8 +1631,8 @@ function drupal_http_header_attributes(array $attributes = array()) { * This keeps the context of the link title ('settings' in the example) for * translators. * - * @param string $text - * The translated link text for the anchor tag. + * @param string|array $text + * The link text for the anchor tag as a translated string or render array. * @param string $path * The internal path or external URL being linked to, such as "node/34" or * "http://example.com/foo". After the url() function is called to construct @@ -1665,10 +1665,9 @@ function drupal_http_header_attributes(array $attributes = array()) { * @see theme_link() */ function l($text, $path, array $options = array()) { - // Build a variables array to keep the structure of the alter consistent with - // theme_link(). + // Start building a structured representation of our link to be altered later. $variables = array( - 'text' => $text, + 'text' => is_array($text) ? drupal_render($text) : $text, 'path' => $path, 'options' => $options, ); diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 011db8d2326..70cce1e9862 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1673,14 +1673,12 @@ 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. However, unlike - * 'text' in l(), both render arrays and strings are supported here. + * See the l() function for information about these variables. * * @see l() */ function theme_link($variables) { - $rendered_text = is_array($variables['text']) ? drupal_render($variables['text']) : $variables['text']; - return l($rendered_text, $variables['path'], $variables['options']); + return l($variables['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 a241a31e949..a502e82823a 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php @@ -134,12 +134,17 @@ class UrlTest extends WebTestBase { } /** - * Tests that theme_link() supports render arrays in 'text' parameter. + * Tests that link functions support render arrays as 'text'. */ - function testLinkNestedRenderArrays() { + function testLinkRenderArrayText() { // Build a link with l() for reference. $l = l('foo', 'http://drupal.org'); + // Test a renderable array passed to l(). + $renderable_text = array('#markup' => 'foo'); + $l_renderable_text = l($renderable_text, 'http://drupal.org'); + $this->assertEqual($l_renderable_text, $l); + // Test a themed link with plain text 'text'. $theme_link_plain_array = array( '#theme' => 'link',