From 00406a5b4ea12535c4cd28646128a2d61a193c92 Mon Sep 17 00:00:00 2001 From: Allen Shaw Date: Tue, 20 Jun 2017 14:39:00 -0500 Subject: [PATCH 1/3] CRM-20751: Support Drupal aliases for event links in Views --- .../civicrm_handler_field_event_link.inc | 38 +++++++---------- .../civicrm_handler_field_link_event.inc | 41 +++++++------------ 2 files changed, 28 insertions(+), 51 deletions(-) diff --git a/modules/views/civicrm/civicrm_handler_field_event_link.inc b/modules/views/civicrm/civicrm_handler_field_event_link.inc index f9f900f87..007e5de17 100644 --- a/modules/views/civicrm/civicrm_handler_field_event_link.inc +++ b/modules/views/civicrm/civicrm_handler_field_event_link.inc @@ -21,7 +21,7 @@ | GNU Affero General Public License or the licensing of CiviCRM, | | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ -*/ + */ /* * Heavily based on anonymous code contribution. No claim. @@ -93,55 +93,45 @@ class civicrm_handler_field_event_link extends views_handler_field { $custom_link = $this->options['custom_link']; } - switch ($link_choice) { // LINKING TO EVENT PAGE (PUBLICLY ACCESSIBLE) case 'page': if (user_access('view event info') && $data !== NULL && $data !== '') { - return civicrm_views_href($data, - 'civicrm/event/info', - "reset=1&id={$values->{$this->aliases['id']}}" - ); + $path = "civicrm/event/info?reset=1&id={$values->{$this->aliases['id']}}"; + return civicrm_views_href($data, drupal_get_path_alias($path), NULL); } // LINKING TO EVENT REGISTRATION PAGE case 'registration': if (user_access('register for events') && $data !== NULL && $data !== '') { - require_once 'CRM/Core/Config.php'; - $config = CRM_Core_Config::singleton(); - if ($enable_cart = - CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, 'enable_cart')) { + if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, 'enable_cart')) { require_once 'CRM/Event/Cart/BAO/EventInCart.php'; //TODO don't call for every row $link = CRM_Event_Cart_BAO_EventInCart::get_registration_link($values->{$this->aliases['id']}); - return civicrm_views_href($link['label'], $link['path'], $link['query']); + $label = $link['label']; + $path = "{$link['path']}?{$link['query']}"; } else { - return civicrm_views_href($data, - 'civicrm/event/register', - "reset=1&id={$values->{$this->aliases['id']}}" - ); + $label = $data; + $path = "civicrm/event/register?reset=1&id={$values->{$this->aliases['id']}}"; } + return civicrm_views_href($label, drupal_get_path_alias($path), NULL); } // LINKING TO EVENT CONFIG PAGE case 'config': if (user_access('access CiviEvent') && $data !== NULL && $data !== '') { - return civicrm_views_href($data, - 'civicrm/event/manage/eventInfo', - "action=update&id={$values->{$this->aliases['id']}}&reset=1" - ); + $path = "civicrm/event/manage/settings?action=update&id={$values->{$this->aliases['id']}}&reset=1"; + return civicrm_views_href($data, drupal_get_path_alias($path), NULL); } // LINKING TO EVENT PARTICIPANTS LIST case 'participants': if (user_access('access CiviEvent') && $data !== NULL && $data !== '') { - return civicrm_views_href($data, - 'civicrm/event/search', - "reset=1&force=1&event={$values->{$this->aliases['id']}}" - ); + $path = "civicrm/event/search?reset=1&force=1&event={$values->{$this->aliases['id']}}"; + return civicrm_views_href($data, drupal_get_path_alias($path), NULL); } // CUSTOM NODE LINKAGE, GOOD FOR LINKING TO OTHER VIEWS WITH AN ARGUMENT @@ -159,5 +149,5 @@ class civicrm_handler_field_event_link extends views_handler_field { function render($values) { return $this->render_link(check_plain($values->{$this->field_alias}), $values); } -} +} diff --git a/modules/views/civicrm/civicrm_handler_field_link_event.inc b/modules/views/civicrm/civicrm_handler_field_link_event.inc index e96a2fbd9..a26a84999 100644 --- a/modules/views/civicrm/civicrm_handler_field_link_event.inc +++ b/modules/views/civicrm/civicrm_handler_field_link_event.inc @@ -21,7 +21,7 @@ | GNU Affero General Public License or the licensing of CiviCRM, | | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ -*/ + */ /* * Copyright (C) 2009 James Rakich @@ -100,62 +100,49 @@ class civicrm_handler_field_link_event extends views_handler_field { $custom_link = $this->options['custom_link']; } - switch ($link_choice) { // LINKING TO EVENT INFO case 'page': if (user_access('view event info') && $link_text !== NULL && $link_text !== '') { - return civicrm_views_href($link_text, - 'civicrm/event/info', - "id={$values->id}&reset=1" - ); + $path = "civicrm/event/info?reset=1&id={$values->{$this->aliases['id']}}"; + return civicrm_views_href($link_text, drupal_get_path_alias($path), NULL); } // LINKING TO EVENT REGISTRATION case 'register': if (user_access('register for events') && $link_text !== NULL && $link_text !== '') { - return civicrm_views_href($link_text, - 'civicrm/event/register', - "id={$values->id}&reset=1" - ); + $path = "civicrm/event/register?reset=1&id={$values->{$this->aliases['id']}}"; + return civicrm_views_href($link_text, drupal_get_path_alias($path), NULL); } // LINKING TO EVENT CONFIG case 'config': if (user_access('access CiviEvent') && $link_text !== NULL && $link_text !== '') { - return civicrm_views_href($link_text, - 'civicrm/event/manage', - "action=update&id={$values->id}&reset=1" - ); + $path = "civicrm/event/manage/settings?action=update&id={$values->{$this->aliases['id']}}&reset=1"; + return civicrm_views_href($link_text, drupal_get_path_alias($path), NULL); } // LINKING TO EVENT PARTICIPANT LISTING case 'listing': if (user_access('view event participants') && $link_text !== NULL && $link_text !== '') { - return civicrm_views_href($link_text, - 'civicrm/event/participant', - "reset=1&id={$values->id}" - ); + $path = "civicrm/event/participant?reset=1&id={$values->id}"; + return civicrm_views_href($link_text, drupal_get_path_alias($path), NULL); } // LINKING TO EVENT PARTICIPANTS case 'participants': if (user_access('edit event participants') && $link_text !== NULL && $link_text !== '') { - return civicrm_views_href($link_text, - 'civicrm/event/search', - "reset=1&force=1&event={$values->id}" - ); + $path = "civicrm/event/search?reset=1&force=1&event={$values->{$this->aliases['id']}}"; + return civicrm_views_href($link_text, drupal_get_path_alias($path), NULL); } // LINKING TO EVENT DELETION case 'delete': if (user_access('access CiviEvent') && $link_text !== NULL && $link_text !== '') { - return civicrm_views_href($link_text, - 'civicrm/event/manage', - "action=delete&id={$values->id}" - ); + $path = "civicrm/event/manage?action=delete&id={$values->id}"; + return civicrm_views_href($link_text, drupal_get_path_alias($path), NULL); } // CUSTOM NODE LINKAGE, GOOD FOR LINKING TO OTHER VIEWS WITH AN ARGUMENT @@ -178,5 +165,5 @@ class civicrm_handler_field_link_event extends views_handler_field { function render($values) { return $this->render_link(NULL, $values); } -} +} From cc24159f23ed56b1a6b6c26ff52f605548095cf6 Mon Sep 17 00:00:00 2001 From: Allen Shaw Date: Wed, 21 Jun 2017 16:02:16 -0500 Subject: [PATCH 2/3] Revert "CRM-20751: Support Drupal aliases for event links in Views" This reverts commit 00406a5b4ea12535c4cd28646128a2d61a193c92. --- .../civicrm_handler_field_event_link.inc | 38 ++++++++++------- .../civicrm_handler_field_link_event.inc | 41 ++++++++++++------- 2 files changed, 51 insertions(+), 28 deletions(-) diff --git a/modules/views/civicrm/civicrm_handler_field_event_link.inc b/modules/views/civicrm/civicrm_handler_field_event_link.inc index 007e5de17..f9f900f87 100644 --- a/modules/views/civicrm/civicrm_handler_field_event_link.inc +++ b/modules/views/civicrm/civicrm_handler_field_event_link.inc @@ -21,7 +21,7 @@ | GNU Affero General Public License or the licensing of CiviCRM, | | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ - */ +*/ /* * Heavily based on anonymous code contribution. No claim. @@ -93,45 +93,55 @@ class civicrm_handler_field_event_link extends views_handler_field { $custom_link = $this->options['custom_link']; } + switch ($link_choice) { // LINKING TO EVENT PAGE (PUBLICLY ACCESSIBLE) case 'page': if (user_access('view event info') && $data !== NULL && $data !== '') { - $path = "civicrm/event/info?reset=1&id={$values->{$this->aliases['id']}}"; - return civicrm_views_href($data, drupal_get_path_alias($path), NULL); + return civicrm_views_href($data, + 'civicrm/event/info', + "reset=1&id={$values->{$this->aliases['id']}}" + ); } // LINKING TO EVENT REGISTRATION PAGE case 'registration': if (user_access('register for events') && $data !== NULL && $data !== '') { - if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, 'enable_cart')) { + require_once 'CRM/Core/Config.php'; + $config = CRM_Core_Config::singleton(); + if ($enable_cart = + CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, 'enable_cart')) { require_once 'CRM/Event/Cart/BAO/EventInCart.php'; //TODO don't call for every row $link = CRM_Event_Cart_BAO_EventInCart::get_registration_link($values->{$this->aliases['id']}); - $label = $link['label']; - $path = "{$link['path']}?{$link['query']}"; + return civicrm_views_href($link['label'], $link['path'], $link['query']); } else { - $label = $data; - $path = "civicrm/event/register?reset=1&id={$values->{$this->aliases['id']}}"; + return civicrm_views_href($data, + 'civicrm/event/register', + "reset=1&id={$values->{$this->aliases['id']}}" + ); } - return civicrm_views_href($label, drupal_get_path_alias($path), NULL); } // LINKING TO EVENT CONFIG PAGE case 'config': if (user_access('access CiviEvent') && $data !== NULL && $data !== '') { - $path = "civicrm/event/manage/settings?action=update&id={$values->{$this->aliases['id']}}&reset=1"; - return civicrm_views_href($data, drupal_get_path_alias($path), NULL); + return civicrm_views_href($data, + 'civicrm/event/manage/eventInfo', + "action=update&id={$values->{$this->aliases['id']}}&reset=1" + ); } // LINKING TO EVENT PARTICIPANTS LIST case 'participants': if (user_access('access CiviEvent') && $data !== NULL && $data !== '') { - $path = "civicrm/event/search?reset=1&force=1&event={$values->{$this->aliases['id']}}"; - return civicrm_views_href($data, drupal_get_path_alias($path), NULL); + return civicrm_views_href($data, + 'civicrm/event/search', + "reset=1&force=1&event={$values->{$this->aliases['id']}}" + ); } // CUSTOM NODE LINKAGE, GOOD FOR LINKING TO OTHER VIEWS WITH AN ARGUMENT @@ -149,5 +159,5 @@ class civicrm_handler_field_event_link extends views_handler_field { function render($values) { return $this->render_link(check_plain($values->{$this->field_alias}), $values); } - } + diff --git a/modules/views/civicrm/civicrm_handler_field_link_event.inc b/modules/views/civicrm/civicrm_handler_field_link_event.inc index a26a84999..e96a2fbd9 100644 --- a/modules/views/civicrm/civicrm_handler_field_link_event.inc +++ b/modules/views/civicrm/civicrm_handler_field_link_event.inc @@ -21,7 +21,7 @@ | GNU Affero General Public License or the licensing of CiviCRM, | | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ - */ +*/ /* * Copyright (C) 2009 James Rakich @@ -100,49 +100,62 @@ class civicrm_handler_field_link_event extends views_handler_field { $custom_link = $this->options['custom_link']; } + switch ($link_choice) { // LINKING TO EVENT INFO case 'page': if (user_access('view event info') && $link_text !== NULL && $link_text !== '') { - $path = "civicrm/event/info?reset=1&id={$values->{$this->aliases['id']}}"; - return civicrm_views_href($link_text, drupal_get_path_alias($path), NULL); + return civicrm_views_href($link_text, + 'civicrm/event/info', + "id={$values->id}&reset=1" + ); } // LINKING TO EVENT REGISTRATION case 'register': if (user_access('register for events') && $link_text !== NULL && $link_text !== '') { - $path = "civicrm/event/register?reset=1&id={$values->{$this->aliases['id']}}"; - return civicrm_views_href($link_text, drupal_get_path_alias($path), NULL); + return civicrm_views_href($link_text, + 'civicrm/event/register', + "id={$values->id}&reset=1" + ); } // LINKING TO EVENT CONFIG case 'config': if (user_access('access CiviEvent') && $link_text !== NULL && $link_text !== '') { - $path = "civicrm/event/manage/settings?action=update&id={$values->{$this->aliases['id']}}&reset=1"; - return civicrm_views_href($link_text, drupal_get_path_alias($path), NULL); + return civicrm_views_href($link_text, + 'civicrm/event/manage', + "action=update&id={$values->id}&reset=1" + ); } // LINKING TO EVENT PARTICIPANT LISTING case 'listing': if (user_access('view event participants') && $link_text !== NULL && $link_text !== '') { - $path = "civicrm/event/participant?reset=1&id={$values->id}"; - return civicrm_views_href($link_text, drupal_get_path_alias($path), NULL); + return civicrm_views_href($link_text, + 'civicrm/event/participant', + "reset=1&id={$values->id}" + ); } // LINKING TO EVENT PARTICIPANTS case 'participants': if (user_access('edit event participants') && $link_text !== NULL && $link_text !== '') { - $path = "civicrm/event/search?reset=1&force=1&event={$values->{$this->aliases['id']}}"; - return civicrm_views_href($link_text, drupal_get_path_alias($path), NULL); + return civicrm_views_href($link_text, + 'civicrm/event/search', + "reset=1&force=1&event={$values->id}" + ); } // LINKING TO EVENT DELETION case 'delete': if (user_access('access CiviEvent') && $link_text !== NULL && $link_text !== '') { - $path = "civicrm/event/manage?action=delete&id={$values->id}"; - return civicrm_views_href($link_text, drupal_get_path_alias($path), NULL); + return civicrm_views_href($link_text, + 'civicrm/event/manage', + "action=delete&id={$values->id}" + ); } // CUSTOM NODE LINKAGE, GOOD FOR LINKING TO OTHER VIEWS WITH AN ARGUMENT @@ -165,5 +178,5 @@ class civicrm_handler_field_link_event extends views_handler_field { function render($values) { return $this->render_link(NULL, $values); } - } + From b7d7ee8add1261dbd74dbd9234585af4b4d5ce1d Mon Sep 17 00:00:00 2001 From: Allen Shaw Date: Wed, 21 Jun 2017 16:03:57 -0500 Subject: [PATCH 3/3] 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; } /**