Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.1013 diff -u -p -r1.1013 common.inc --- includes/common.inc 11 Oct 2009 06:05:53 -0000 1.1013 +++ includes/common.inc 13 Oct 2009 00:16:14 -0000 @@ -2578,13 +2578,71 @@ function drupal_attributes(array $attrib * an HTML string containing a link to the given path. */ function l($text, $path, array $options = array()) { + global $theme; + static $theme_function = 'theme_link', $initialized; + + $variables = array( + 'text' => $text, + 'path' => $path, + 'options' => $options, + ); + + // If the theme system is not initialized yet, then theme('link') cannot be + // called and it needs to be called directly. Also, since l() is called very + // often during a single page request, we statically cache the theme function + // to directly invoke them in subsequent calls. + if (!isset($initialized) && isset($theme)) { + $initialized = TRUE; + // Theme hooks can define include files, but those only need to be loaded + // once per request. A single call to theme() is fine, but subsequent + // invocations of l() will avoid this overhead. + $return = theme('link', $variables); + + // Retrieve the theme function. Because preprocessing and processing does + // not make sense here, we skip them. + $registry = theme_get_registry(); + if (isset($registry) && isset($registry['link']['function']) && function_exists($registry['link']['function'])) { + $theme_function = $registry['link']['function']; + } + } + // In subsequent calls to l(), we mimic theme('link') using the cached data. + else { + $return = $theme_function($variables); + } + + return $return; +} + +/** + * Format an internal Drupal link. + * + * @param $variables + * An associative array containing: + * - text: The link text to output. + * - path: The URL path component to link to. + * - options: (optional) An array of options to pass to url(). + * See l() for more information. + * + * @return + * A HTML string containing a link to the given path. + * + * @ingroup themeable + * + * @todo If it is impossible to call l() before the theme system is initialized, + * then move this function into theme.inc. + */ +function theme_link($variables) { global $language_url; + $text = $variables['text']; + $path = $variables['path']; + $options = $variables['options']; + // Merge in defaults. $options += array( - 'attributes' => array(), - 'html' => FALSE, - ); + 'attributes' => array(), + 'html' => FALSE, + ); // Append active class. if (($path == $_GET['q'] || ($path == '' && drupal_is_front_page())) && @@ -4857,6 +4915,9 @@ function drupal_common_theme() { 'status_messages' => array( 'arguments' => array('display' => NULL), ), + 'link' => array( + 'arguments' => array('text' => NULL, 'path' => NULL, 'options' => array()), + ), 'links' => array( 'arguments' => array('links' => NULL, 'attributes' => array('class' => array('links')), 'heading' => array()), ), Index: modules/simpletest/tests/common.test =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common.test,v retrieving revision 1.83 diff -u -p -r1.83 common.test --- modules/simpletest/tests/common.test 11 Oct 2009 02:14:43 -0000 1.83 +++ modules/simpletest/tests/common.test 13 Oct 2009 00:05:28 -0000 @@ -4,7 +4,7 @@ /** * Tests for URL generation functions. */ -class CommonURLUnitTest extends DrupalUnitTestCase { +class CommonURLUnitTest extends DrupalWebTestCase { public static function getInfo() { return array( 'name' => 'URL generation tests',