From 9477885d60986b4117f2f66840ca53b0f85a1864 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 25 Jul 2023 01:00:59 -0700 Subject: [PATCH] Civi::url() - Add support for `default://` URIs --- Civi.php | 1 + Civi/Core/Url.php | 3 +-- tests/phpunit/E2E/Core/PathUrlTest.php | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Civi.php b/Civi.php index 1a23839e58..2ee7ccad10 100644 --- a/Civi.php +++ b/Civi.php @@ -269,6 +269,7 @@ class Civi { * - 'backend://' (Back-end page-route for staff) * - 'service://` (Web-service page-route for automated integrations; aka webhooks and IPNs) * - 'current://' (Whichever UI is currently active) + * - 'default://'(Whichever UI is recorded in the metadata) * - 'asset://' (Static asset-file; see \Civi::paths()) * - 'assetBuilder://' (Dynamically-generated asset-file; see \Civi\Core\AssetBuilder) * - 'ext://' (Static asset-file provided by an extension) diff --git a/Civi/Core/Url.php b/Civi/Core/Url.php index 6bd147f29f..9f6fd45d24 100644 --- a/Civi/Core/Url.php +++ b/Civi/Core/Url.php @@ -520,8 +520,7 @@ final class Url implements \JsonSerializable { } if ($scheme === 'default') { - // TODO Use metadata to pick $scheme = 'frontend' or 'backend' or 'service'; - throw new \RuntimeException("FIXME: Implement lookup for default "); + $scheme = \CRM_Core_Menu::isPublicRoute($this->getPath()) ? 'frontend' : 'backend'; } switch ($scheme) { diff --git a/tests/phpunit/E2E/Core/PathUrlTest.php b/tests/phpunit/E2E/Core/PathUrlTest.php index 28ce71e83b..98a316fa96 100644 --- a/tests/phpunit/E2E/Core/PathUrlTest.php +++ b/tests/phpunit/E2E/Core/PathUrlTest.php @@ -139,6 +139,16 @@ class PathUrlTest extends \CiviEndToEndTestCase { // For purposes of this test, it doesn't matter if "current" is frontend or backend - as long as it's consistent. } + public function testUrl_DefaultUI(): void { + $adminDefault = (string) \Civi::url('default://civicrm/admin'); + $adminBackend = (string) \Civi::url('backend://civicrm/admin'); + $this->assertEquals($adminBackend, $adminDefault, "civicrm/admin should default to backend"); + + $userDefault = (string) \Civi::url('default://civicrm/user'); + $userBackend = (string) \Civi::url('frontend://civicrm/user'); + $this->assertEquals($userBackend, $userDefault, "civicrm/user should default to frontend"); + } + /** * @param string $expectContentRegex * @param string $url -- 2.25.1