From 6541c24d6f1acac3893dddd594678dfca7e699ee Mon Sep 17 00:00:00 2001 From: Mathieu Lutfy Date: Tue, 10 Sep 2019 12:45:45 -0400 Subject: [PATCH] dev/drupal#52 Override getUrlPath() for Drupal8 --- CRM/Utils/System.php | 10 ++++++++-- CRM/Utils/System/Drupal8.php | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index b5293236880..b69a90502fa 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -306,8 +306,14 @@ public static function url( * @return string|null */ public static function getUrlPath() { - if (isset($_GET[CRM_Core_Config::singleton()->userFrameworkURLVar])) { - return $_GET[CRM_Core_Config::singleton()->userFrameworkURLVar]; + $config = CRM_Core_Config::singleton(); + + if (function_exists($config->userSystem->getUrlPath())) { + return $config->userSystem->getUrlPath(); + } + + if (isset($_GET[$config->userFrameworkURLVar])) { + return $_GET[$config->userFrameworkURLVar]; } return NULL; } diff --git a/CRM/Utils/System/Drupal8.php b/CRM/Utils/System/Drupal8.php index 38ed2933c67..20de70be920 100644 --- a/CRM/Utils/System/Drupal8.php +++ b/CRM/Utils/System/Drupal8.php @@ -802,4 +802,29 @@ public function languageNegotiationURL($url, $addLanguagePart = TRUE, $removeLan return $url; } + /** + * @inheritDoc + */ + public function getUrlPath() { + if (!class_exists('Drupal') || !\Drupal::hasContainer()) { + return NULL; + } + + $path = \Drupal::service('path.current')->getPath(); + + // Remove '/' prefix for compatibility with CiviCRM d7-style assumptions + // Ex: '/civicrm/contribute' becomes 'civicrm/contribute' + if ($path) { + $path = substr($path, 1); + + // Remove the language prefix, if present + // The URL returned by Drupal randomly includes the language prefix, sometimes not. + if (preg_match('/^\w\w\//', $path)) { + $path = substr($path, 3); + } + } + + return $path; + } + }