From b7d7ee8add1261dbd74dbd9234585af4b4d5ce1d Mon Sep 17 00:00:00 2001 From: Allen Shaw Date: Wed, 21 Jun 2017 16:03:57 -0500 Subject: [PATCH] Fix CRM-20751: Add Drupal alias support for all Views links. --- modules/views/civicrm.views.inc | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/modules/views/civicrm.views.inc b/modules/views/civicrm.views.inc index de5fbc09d..e8f6b4181 100644 --- a/modules/views/civicrm.views.inc +++ b/modules/views/civicrm.views.inc @@ -142,9 +142,8 @@ function civicrm_views_data_alter(&$data) { * @return String path to CiviCRM */ function civicrm_views_href($text, $path, $query) { - civicrm_initialize(); - require_once 'CRM/Utils/System.php'; - return CRM_Utils_System::href($text, $path, $query); + $url = civicrm_views_url($path, $query); + return "$text"; } /** @@ -159,9 +158,24 @@ function civicrm_views_href($text, $path, $query) { * @return string an HTML string containing a link to the given path. */ function civicrm_views_url($path, $query, $absolute = FALSE) { - civicrm_initialize(); - require_once 'CRM/Utils/System.php'; - return CRM_Utils_System::url($path, $query, $absolute); + // Force alphabetical order of query params, for consistent support + // of Drupal aliases. This is required because $query is a string that may + // be coming to us in any order; but query parameter order matters when + // passing that query string as part of $path in url($path). Admittedly it's + // not common to passt the query string as part of $path in url($path) (you + // would normally pass it as $options['query'] in url($path, $options)), but + // doing so is required for Drupal alias support. + if (!empty($query)) { + parse_str($query, $query_data); + ksort($query_data); + $query = http_build_query($query_data); + $path .= "?{$query}"; + } + $options = array( + 'absolute' => $absolute, + ); + $url = url($path, $options); + return $url; } /**