Skip to content

Commit

Permalink
Fix CRM-20751: Add Drupal alias support for all Views links.
Browse files Browse the repository at this point in the history
  • Loading branch information
twomice committed Jun 21, 2017
1 parent cc24159 commit b7d7ee8
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions modules/views/civicrm.views.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<a href=\"$url\">$text</a>";
}

/**
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit b7d7ee8

Please sign in to comment.