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

8.0.x
catch 2013-06-02 17:12:36 +01:00
parent 81ed3ecb0f
commit a078c23800
3 changed files with 13 additions and 11 deletions

View File

@ -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,
);

View File

@ -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']);
}
/**

View File

@ -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',