From: Torrance Date: Tue, 14 Apr 2015 05:53:58 +0000 (+1200) Subject: Allow for url's that are not Drupal routes; handle 'path?query' special case. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=756ad86000ae7442ba5f83fb0f6c8a16e6524647;p=civicrm-core.git Allow for url's that are not Drupal routes; handle 'path?query' special case. --- diff --git a/CRM/Utils/System/Drupal8.php b/CRM/Utils/System/Drupal8.php index e7a2803557..097389cde9 100644 --- a/CRM/Utils/System/Drupal8.php +++ b/CRM/Utils/System/Drupal8.php @@ -317,24 +317,35 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase { $query = '', $absolute = FALSE, $fragment = NULL, - $htmlize = TRUE, + $htmlize = FALSE, $frontend = FALSE, $forceBackend = FALSE ) { $query = html_entity_decode($query); + $url = \Drupal\civicrm\CivicrmHelper::parseURL("{$path}?{$query}"); + // Not all links that CiviCRM generates are Drupal routes, so we use the weaker ::fromUri method. try { - $url = \Drupal::url($url['route_name'], array(), array( + $url = \Drupal\Core\Url::fromUri("base:{$url['path']}", [ 'query' => $url['query'], - 'absolute' => $absolute, 'fragment' => $fragment, - )); + 'absolute' => $absolute, + ])->toString(); } catch (Exception $e) { + // @Todo: log to watchdog $url = ''; } + // Special case: CiviCRM passes us "*path*?*query*" as a skeleton, but asterisks + // are invalid and Drupal will attempt to escape them. We unescape them here: + if ($path == '*path*') { + // First remove trailing equals sign that has been added since the key '?*query*' has no value. + $url = rtrim($url, '='); + $url = urldecode($url); + } + if ($htmlize) { $url = htmlentities($url); }