Commit a078c238 authored by catch's avatar catch

Issue #1987114 by thedavidmeister: Allow l() to accept a renderable array for $text.

parent 81ed3ecb
......@@ -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,
);
......
......@@ -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']);
}
/**
......
......@@ -134,12 +134,17 @@ function testLinkCustomClass() {
}
/**
* 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',
......
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