diff --git a/core/includes/common.inc b/core/includes/common.inc index 2e1bfa5..a692ef2 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1849,38 +1849,6 @@ function url_is_external($path) { } /** - * Returns TRUE if the current URL matches the given path and options. - * - * @param string $path - * An internal path or external url as could be used by url(). - * @param array $options - * An associative array of options as could be used by url(). - * - * @return bool - * Boolean TRUE or FALSE, where TRUE indicates an active path. - * - * @see url() - */ -function url_is_active($path, $options = array()) { - // Merge in defaults. - $options += array( - 'query' => array(), - 'language' => NULL, - ); - - // A path is only active if it corresponds to the current path, the - // language of the path is equal to the current language, and if the - // query parameters of the URL equal those of the current request, since the - // same request with different query parameters may yield a different page - // (e.g., pagers). - $path_match = $path == current_path() || ($path == '' && drupal_is_front_page()); - $lang_match = empty($options['language']) || $options['language']->langcode == language(LANGUAGE_TYPE_URL)->langcode; - $query_match = Drupal::service('request')->query->all() == $options['query']; - - return $path_match && $lang_match && $query_match; -} - -/** * Formats an attribute string for an HTTP header. * * @param $attributes @@ -1960,15 +1928,25 @@ function l($text, $path, array $options = array()) { 'options' => $options, ); - // Merge in defaults. + // Merge in default options. $variables['options'] += array( 'attributes' => array(), 'query' => array(), 'html' => FALSE, + 'language' => NULL, ); // Add 'active' class if appropriate. - if ($variables['url_is_active'] = url_is_active($variables['path'], $variables['options'])) { + // A path is only active if it corresponds to the current path, the + // language of the path is equal to the current language, and if the + // query parameters of the URL equal those of the current request, since the + // same request with different query parameters may yield a different page + // (e.g., pagers). This logic is inline to ensure that l() remains fast. + $path_match = $path == current_path() || ($path == '' && drupal_is_front_page()); + $lang_match = empty($variables['options']['language']) || $variables['options']['language']->langcode == language(LANGUAGE_TYPE_URL)->langcode; + $query_match = Drupal::service('request')->query->all() == $variables['options']['query']; + + if ($variables['url_is_active'] = $path_match && $lang_match && $query_match) { $variables['options']['attributes']['class'][] = 'active'; }