l

Versions
4.6 – 5
l($text, $path, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE, $html = FALSE)
6
l($text, $path, $options = array())
7
l($text, $path, array $options = array())

Format an internal Drupal link.

This function correctly handles aliased paths, and allows themes to highlight links to the current page correctly, so all internal links output by modules should be generated by this function if possible.

Parameters

$text The text to be enclosed with the anchor tag.

$path The Drupal path being linked to, such as "admin/content". Can be an external or internal URL.

  • If you provide the full URL, it will be considered an external URL.
  • If you provide only the path (e.g. "admin/content"), it is considered an internal link. In this case, it must be a system URL as the url() function will generate the alias.
  • If you provide '<front>', it generates a link to the site's base URL (again via the url() function).
  • If you provide a path, and 'alias' is set to TRUE (see below), it is used as is.

$options An associative array of additional options, with the following keys:

  • 'attributes' An associative array of HTML attributes to apply to the anchor tag.
  • 'query' A query string to append to the link, or an array of query key/value properties.
  • 'fragment' A fragment identifier (named anchor) to append to the link. Do not include the '#' character.
  • 'absolute' (default FALSE) Whether to force the output to be an absolute link (beginning with http:). Useful for links that will be displayed outside the site, such as in an RSS feed.
  • 'html' (default FALSE) Whether $text is HTML, or just plain-text. For example for making an image a link, this must be set to TRUE, or else you will see the escaped HTML.
  • 'alias' (default FALSE) Whether the given path is an alias already.

Return value

an HTML string containing a link to the given path.

▾ 118 functions call l()

actions_synchronize in includes/actions.inc
Synchronizes actions that are provided by modules in hook_action_info().
aggregator_aggregator_parse in modules/aggregator/aggregator.parser.inc
Implement hook_aggregator_parse().
aggregator_form_category_submit in modules/aggregator/aggregator.admin.inc
Process aggregator_form_category form submissions.
aggregator_form_feed_submit in modules/aggregator/aggregator.admin.inc
Process aggregator_form_feed() form submissions.
aggregator_view in modules/aggregator/aggregator.admin.inc
Displays the aggregator administration page.
block_help in modules/block/block.module
Implement hook_help().
blog_page_last in modules/blog/blog.pages.inc
Menu callback; displays a Drupal page containing recent blog entries of all users.
blog_page_user in modules/blog/blog.pages.inc
Menu callback; displays a Drupal page containing recent blog entries of a given user.
blog_user_view in modules/blog/blog.module
Implement hook_user_view().
blog_view in modules/blog/blog.module
Implement hook_view().
book_admin_edit_submit in modules/book/book.admin.inc
Handle submission of the book administrative page form.
book_admin_overview in modules/book/book.admin.inc
Returns an administrative overview of all books.
book_render in modules/book/book.pages.inc
Menu callback; prints a listing of all books.
comment_admin_overview_submit in modules/comment/comment.admin.inc
Process comment_admin_overview form submissions.
comment_reply in modules/comment/comment.pages.inc
This function is responsible for generating a comment reply form. There are several cases that have to be handled, including:
comment_save in modules/comment/comment.module
Accepts a submission of new or changed comment content.
confirm_form in modules/system/system.module
Output a confirmation form
contact_category_edit_form_submit in modules/contact/contact.admin.inc
Process the contact category edit page form submission.
contact_category_list in modules/contact/contact.admin.inc
Categories/list tab.
dashboard_admin in modules/dashboard/dashboard.module
Dashboard page callback.
dblog_event in modules/dblog/dblog.admin.inc
Menu callback; displays details about a log message.
dblog_overview in modules/dblog/dblog.admin.inc
Menu callback; displays a listing of log messages.
drupal_pre_render_link in includes/common.inc
#pre_render callback to render a link into #markup.
field_ui_fields_list in modules/field_ui/field_ui.admin.inc
Menu callback; lists all defined fields for quick reference.
filter_permission in modules/filter/filter.module
Implement hook_permission().
forum_node_view in modules/forum/forum.module
Implement hook_node_view().
forum_overview in modules/forum/forum.admin.inc
Returns an overview list of existing forums and containers
help_links_as_list in modules/help/help.admin.inc
hook_requirements in modules/system/system.api.php
Check installation requirements and do status reporting.
hook_user_view in modules/user/user.api.php
The user's account information is being displayed.
locale_date_format_language_overview_page in modules/locale/locale.module
Display edit date format links for each language.
menu_edit_item in modules/menu/menu.admin.inc
Menu callback; Build the menu link editing form.
menu_get_active_breadcrumb in includes/menu.inc
Get the breadcrumb for the current page, as determined by the active trail.
menu_overview_page in modules/menu/menu.admin.inc
Menu callback which shows an overview page of all the custom menus and their descriptions.
node_form_submit in modules/node/node.pages.inc
node_overview_types in modules/node/content_types.inc
Displays the content type admin overview page.
node_page_default in modules/node/node.module
Menu callback; Generate a listing of promoted nodes.
node_requirements in modules/node/node.module
Implement hook_requirements().
node_revision_overview in modules/node/node.pages.inc
Generate an overview table of older revisions of a node.
node_title_list in modules/node/node.module
Gather a listing of links to nodes.
node_type_form_submit in modules/node/content_types.inc
Implement hook_form_submit().
openid_user_identities in modules/openid/openid.pages.inc
Menu callback; Manage OpenID identities for the specified user.
path_admin_overview in modules/path/path.admin.inc
Return a listing of all defined URL aliases.
php_install in modules/php/php.install
Implement hook_install().
poll_page in modules/poll/poll.pages.inc
Menu callback to provide a simple list of all polls available.
profile_admin_overview in modules/profile/profile.admin.inc
Form builder to display a listing of all editable profile fields.
profile_block_view in modules/profile/profile.module
Implement hook_block_view().
profile_field_delete_submit in modules/profile/profile.admin.inc
Process a field delete form submission.
profile_field_form_submit in modules/profile/profile.admin.inc
Process profile_field_form submissions.
profile_view_field in modules/profile/profile.module
search_view in modules/search/search.pages.inc
Menu callback; presents the search form and/or search results.
seven_admin_block_content in themes/seven/template.php
Override of theme_admin_block_content().
seven_node_add_list in themes/seven/template.php
Display the list of available node types for node creation.
shortcut_set_customize in modules/shortcut/shortcut.admin.inc
Menu callback; Build the form for customizing shortcut sets.
statistics_access_log in modules/statistics/statistics.admin.inc
Menu callback; Displays recent page accesses.
statistics_node_tracker in modules/statistics/statistics.pages.inc
statistics_recent_hits in modules/statistics/statistics.admin.inc
Menu callback; presents the "recent hits" page.
statistics_top_visitors in modules/statistics/statistics.admin.inc
Menu callback; presents the "top visitors" page.
statistics_user_tracker in modules/statistics/statistics.pages.inc
syslog_form_system_logging_settings_alter in modules/syslog/syslog.module
Implement hook_form_FORM_ID_alter().
system_actions_manage in modules/system/system.admin.inc
Menu callback; Displays an overview of available and configured actions.
system_admin_by_module in modules/system/system.admin.inc
Menu callback; prints a listing of admin tasks for each installed module.
system_date_time_formats in modules/system/system.admin.inc
Displays the date format strings overview page.
system_get_module_admin_tasks in modules/system/system.module
Generate a list of tasks offered by a specified module.
system_help in modules/system/system.module
Implement hook_help().
system_ip_blocking in modules/system/system.admin.inc
Menu callback. Display blocked IP addresses.
system_main_admin_page in modules/system/system.admin.inc
Menu callback; Provide the administration overview page.
system_requirements in modules/system/system.install
Test and report Drupal installation requirements.
system_token_info in modules/system/system.tokens.inc
Implement hook_token_info().
system_update_7013 in modules/system/system.install
Convert default time zone offset to default time zone name.
tablesort_header in includes/tablesort.inc
Format a column header.
taxonomy_form_term_submit in modules/taxonomy/taxonomy.admin.inc
Submit handler to insert or update a term.
taxonomy_form_vocabulary_submit in modules/taxonomy/taxonomy.admin.inc
Accept the form submission for a vocabulary and save the results.
taxonomy_term_page in modules/taxonomy/taxonomy.pages.inc
Menu callback; displays all nodes associated with a term.
template_preprocess_aggregator_feed_source in modules/aggregator/aggregator.pages.inc
Process variables for aggregator-feed-source.tpl.php.
template_preprocess_aggregator_item in modules/aggregator/aggregator.pages.inc
Process variables for aggregator-item.tpl.php.
template_preprocess_comment in modules/comment/comment.module
Process variables for comment.tpl.php.
template_preprocess_forums in modules/forum/forum.module
Process variables for forums.tpl.php
template_preprocess_forum_topic_list in modules/forum/forum.module
Preprocess variables to format the topic listing.
template_preprocess_user_picture in modules/user/user.module
Process variables for user-picture.tpl.php.
theme_admin_block_content in modules/system/system.admin.inc
This function formats the content of an administrative block.
theme_book_admin_table in modules/book/book.admin.inc
Theme function for the book administration page form.
theme_book_title_link in modules/book/book.module
Generate the HTML output for a link to a book title when used as a block title.
theme_comment_block in modules/comment/comment.module
Returns a formatted list of recent comments to be displayed in the comment block.
theme_field_formatter_image_link_content in modules/image/image.field.inc
Theme function for 'image_link_content' image field formatter.
theme_field_formatter_image_link_file in modules/image/image.field.inc
Theme function for 'image_link_file' image field formatter.
theme_field_formatter_taxonomy_term_link in modules/taxonomy/taxonomy.module
Theme function for 'link' term field formatter.
theme_file_link in modules/file/file.module
Output a link to a file.
theme_filter_tips_more_info in modules/filter/filter.module
Format a link to the more extensive filter tips.
theme_image_style_list in modules/image/image.admin.inc
Display the page containing the list of image styles.
theme_image_style_preview in modules/image/image.admin.inc
Theme callback for displaying a preview of an image style.
theme_links in includes/theme.inc
Return a themed set of links.
theme_locale_languages_overview_form in includes/locale.inc
Theme the language overview form.
theme_menu_link in includes/menu.inc
Generate the HTML output for a menu link and submenu.
theme_menu_local_action in includes/menu.inc
Generate the HTML output for a single local action link.
theme_menu_local_task in includes/menu.inc
Generate the HTML output for a single local task link.
theme_node_add_list in modules/node/node.pages.inc
Display the list of available node types for node creation.
theme_pager_link in includes/pager.inc
Format a link to a specific query result page.
theme_system_compact_link in modules/system/system.module
Display the link to show or hide inline help descriptions.
theme_update_last_check in modules/update/update.module
Render the HTML to display the last time we checked for update data.
theme_update_report in modules/update/update.report.inc
Theme project status report.
theme_update_version in modules/update/update.report.inc
Theme the version display of a project.
theme_upload_attachments in modules/upload/upload.module
Displays file attachments in table
theme_username in includes/theme.inc
Format a username.
theme_user_admin_new_role in modules/user/user.admin.inc
Theme the new-role form.
tracker_page in modules/tracker/tracker.pages.inc
Menu callback; prints a listing of active nodes on the site.
translation_node_overview in modules/translation/translation.pages.inc
Overview page for a node's translations.
trigger_assign_form in modules/trigger/trigger.admin.inc
Returns the form for assigning an action to a trigger.
update_manager_update_form in modules/update/update.manager.inc
Build the form for the update manager page to update existing projects.
user_login_block in modules/user/user.module
user_register_submit in modules/user/user.module
Submit handler for the user registration form.
user_update_7002 in modules/user/user.install
Convert user time zones from time zone offsets to time zone names.
_locale_translate_seek in includes/locale.inc
Perform a string search and display results in a table
_menu_overview_tree_form in modules/menu/menu.admin.inc
Recursive helper function for menu_overview_form().
_node_mass_update_batch_process in modules/node/node.admin.inc
Node Mass Update Batch operation
_openid_user_login_form_alter in modules/openid/openid.module
_statistics_link in modules/statistics/statistics.module
It is possible to adjust the width of columns generated by the statistics module.
_update_requirement_check in modules/update/update.module
Private helper method to fill in the requirements array.

Code

includes/common.inc, line 2690

<?php
function l($text, $path, array $options = array()) {
  global $language_url;
  static $use_theme = NULL;

  // Merge in defaults.
  $options += array(
      'attributes' => array(),
      'html' => FALSE,
    );

  // Append active class.
  if (($path == $_GET['q'] || ($path == '<front>' && drupal_is_front_page())) &&
      (empty($options['language']) || $options['language']->language == $language_url->language)) {
    $options['attributes']['class'][] = 'active';
  }

  // Remove all HTML and PHP tags from a tooltip. For best performance, we act only
  // if a quick strpos() pre-check gave a suspicion (because strip_tags() is expensive).
  if (isset($options['attributes']['title']) && strpos($options['attributes']['title'], '<') !== FALSE) {
    $options['attributes']['title'] = strip_tags($options['attributes']['title']);
  }

  // Determine if rendering of the link is to be done with a theme function
  // or the inline default. Inline is faster, but if the theme system has been
  // loaded and a module or theme implements a preprocess or process function
  // or overrides the theme_link() function, then invoke theme(). Preliminary
  // benchmarks indicate that invoking theme() can slow down the l() function
  // by 20% or more, and that some of the link-heavy Drupal pages spend more
  // than 10% of the total page request time in the l() function.
  if (!isset($use_theme) && function_exists('theme')) {
    // Allow edge cases to prevent theme initialization and force inline link
    // rendering.
    if (variable_get('theme_link', TRUE)) {
      drupal_theme_initialize();
      $registry = theme_get_registry();
      // We don't want to duplicate functionality that's in theme(), so any
      // hint of a module or theme doing anything at all special with the 'link'
      // theme hook should simply result in theme() being called. This includes
      // the overriding of theme_link() with an alternate function or template,
      // the presence of preprocess or process functions, or the presence of
      // include files.
      $use_theme = !isset($registry['link']['function']) || ($registry['link']['function'] != 'theme_link');
      $use_theme = $use_theme || !empty($registry['link']['preprocess functions']) || !empty($registry['link']['process functions']) || !empty($registry['link']['includes']);
    }
    else {
      $use_theme = FALSE;
    }
  }
  if ($use_theme) {
    return theme('link', array('text' => $text, 'path' => $path, 'options' => $options));
  }
  return '<a href="' . check_plain(url($path, $options)) . '"' . drupal_attributes($options['attributes']) . '>' . ($options['html'] ? $text : check_plain($text)) . '</a>';
}
?>

$options['language'] isn't

seutje - Fri, 2009-10-09 13:35

$options['language'] isn't mentioned in the parameters, use as following:

<?php
$title
= t('Some title');
$path = 'some/path';
$options = array(
 
'query' => array(
   
'somekey' => 'somevalue'
 
),
 
'language' => $language->language
);
$link = l($title, $path, $options);
?>

where $language->language is a valid langcode

Actually the 'language'

Jose Reyero - Thu, 2009-10-29 00:04

Actually the 'language' option should be the full language object ('language' => $language);

Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.