diff --git a/core/includes/common.inc b/core/includes/common.inc
index e2a28c3..3404082 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -1912,10 +1912,14 @@ function drupal_http_header_attributes(array $attributes = array()) {
* internal to the site, $options['language'] is used to determine whether
* the link is "active", or pointing to the current page (the language as
* well as the path must match). This element is also used by url().
+ * - 'render': A boolean value indicating whether the the function should
+ * return a rendered string (TRUE) or a structured array for rendering later
+ * (FALSE). Defaults to TRUE.
* - Additional $options elements used by the url() function.
*
- * @return string
- * An HTML string containing a link to the given path.
+ * @return string|array
+ * Either an HTML string containing a link to the given path or an array for
+ * containing the structure of the element for rendering later.
*
* @see url()
* @see theme_link()
@@ -1935,6 +1939,7 @@ function l($text, $path, array $options = array()) {
'query' => array(),
'html' => FALSE,
'language' => NULL,
+ 'render' => TRUE,
);
// Because l() is called very often we statically cache values that require an
@@ -1977,18 +1982,23 @@ function l($text, $path, array $options = array()) {
// Allow other modules to modify the structure of the link.
Drupal::service('module_handler')->alter('link', $variables);
- // Move attributes out of options. url() doesn't need them.
- $attributes = new Attribute($variables['options']['attributes']);
- unset($variables['options']['attributes']);
+ // Convert attributes to Attribute object.
+ $variables['options']['attributes'] = new Attribute($variables['options']['attributes']);
- // The result of url() is a plain-text URL. Because we are using it here
- // in an HTML argument context, we need to encode it properly.
- $url = check_plain(url($variables['path'], $variables['options']));
+ // The result of url() is a plain-text URL. Because we are using it here in an
+ // HTML argument context, we need to encode it properly.
+ $variables['url'] = check_plain(url($variables['path'], $variables['options']));
// Sanitize the link text if necessary.
- $text = $variables['options']['html'] ? $variables['text'] : check_plain($variables['text']);
+ $variables['text'] = $variables['options']['html'] ? $variables['text'] : check_plain($variables['text']);
+
+ // Return the complete variables array if render is FALSE.
+ if ($variables['options']['render'] === FALSE) {
+ return $variables;
+ }
- return '' . $text . '';
+ // Return the link HTML as a string.
+ return '' . $variables['text'] . '';
}
/**