Issue #1987114 by thedavidmeister: Allow l() to accept a renderable array for $text.
parent
81ed3ecb0f
commit
a078c23800
|
@ -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
|
* This keeps the context of the link title ('settings' in the example) for
|
||||||
* translators.
|
* translators.
|
||||||
*
|
*
|
||||||
* @param string $text
|
* @param string|array $text
|
||||||
* The translated link text for the anchor tag.
|
* The link text for the anchor tag as a translated string or render array.
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* The internal path or external URL being linked to, such as "node/34" or
|
* 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
|
* "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()
|
* @see theme_link()
|
||||||
*/
|
*/
|
||||||
function l($text, $path, array $options = array()) {
|
function l($text, $path, array $options = array()) {
|
||||||
// Build a variables array to keep the structure of the alter consistent with
|
// Start building a structured representation of our link to be altered later.
|
||||||
// theme_link().
|
|
||||||
$variables = array(
|
$variables = array(
|
||||||
'text' => $text,
|
'text' => is_array($text) ? drupal_render($text) : $text,
|
||||||
'path' => $path,
|
'path' => $path,
|
||||||
'options' => $options,
|
'options' => $options,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1673,14 +1673,12 @@ function theme_status_messages($variables) {
|
||||||
*
|
*
|
||||||
* @param $variables
|
* @param $variables
|
||||||
* An associative array containing the keys 'text', 'path', and 'options'.
|
* An associative array containing the keys 'text', 'path', and 'options'.
|
||||||
* See the l() function for information about these variables. However, unlike
|
* See the l() function for information about these variables.
|
||||||
* 'text' in l(), both render arrays and strings are supported here.
|
|
||||||
*
|
*
|
||||||
* @see l()
|
* @see l()
|
||||||
*/
|
*/
|
||||||
function theme_link($variables) {
|
function theme_link($variables) {
|
||||||
$rendered_text = is_array($variables['text']) ? drupal_render($variables['text']) : $variables['text'];
|
return l($variables['text'], $variables['path'], $variables['options']);
|
||||||
return l($rendered_text, $variables['path'], $variables['options']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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.
|
// Build a link with l() for reference.
|
||||||
$l = l('foo', 'http://drupal.org');
|
$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'.
|
// Test a themed link with plain text 'text'.
|
||||||
$theme_link_plain_array = array(
|
$theme_link_plain_array = array(
|
||||||
'#theme' => 'link',
|
'#theme' => 'link',
|
||||||
|
|
Loading…
Reference in New Issue