Skip to content

Commit

Permalink
dev/drupal#52 Override getUrlPath() for Drupal8
Browse files Browse the repository at this point in the history
  • Loading branch information
mlutfy committed Sep 10, 2019
1 parent b9affcb commit 6541c24
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
10 changes: 8 additions & 2 deletions CRM/Utils/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
25 changes: 25 additions & 0 deletions CRM/Utils/System/Drupal8.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

0 comments on commit 6541c24

Please sign in to comment.