diff --git a/core/includes/common.inc b/core/includes/common.inc index a692ef29f8ce99bde79e17345f9bf82bb941a53d..9e98fc90889f3604a83d4bb6f6c5c9bb27116bf2 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1936,17 +1936,18 @@ function l($text, $path, array $options = array()) { 'language' => NULL, ); - // Add 'active' class if appropriate. - // 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) { + // Determine whether this link is "active', meaning that it links to the + // current page. It is important that we stop checking "active" conditions if + // we know the link is not active. This helps ensure that l() remains fast. + // An active link's path is equal to the current path. + $variables['url_is_active'] = ($path == current_path() || ($path == '' && drupal_is_front_page())) + // The language of an active link is equal to the current language. + && (empty($variables['options']['language']) || $variables['options']['language']->langcode == language(LANGUAGE_TYPE_URL)->langcode) + // The query parameters of an active link are equal to the current parameters. + && (Drupal::service('request')->query->all() == $variables['options']['query']); + + // Add the "active" class if appropriate. + if ($variables['url_is_active']) { $variables['options']['attributes']['class'][] = 'active'; }