New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(dev/core#4433) WordPress::url() - By default, choose frontend or backend based on route #25476
Conversation
(Standard links)
|
Requested a supplemental run of (UPDATE) After pushing 4b904de, fired another run: https://test.civicrm.org/job/CiviCRM-Manual-Test/38/ |
@totten I think that param exists because two different URLs can cause CiviCRM to render the same content in different contexts, e.g.
FWIW I have never used the latter except by accidentally clicking an Event title on CiviCRM's "Manage Events" screen. I guess the latter URL is the result of Also FWIW these params existed before I started rewriting |
Thanks for that example. I played around in the "Manage Events" area and (for comparison) also played around in "Manage Contribution Pages" and "Profiles". I think we can make the case for the title link in "Manage Events" to change, e.g.
But since I looked at those other examples... here's another oddball. |
@totten Yeah, it's definitely confusing that different components do different things. Good to have teased out the scope of the issue, though, but hard to see a consistent solution. |
The main obstacle to this PR was the existence multi-homed routes (eg So I'll close this. The near-term test-failure is mitigated by #26772, and the bigger DX issue has been split out as https://lab.civicrm.org/dev/core/-/issues/4433 with current draft #26861. |
Overview
(See also: https://lab.civicrm.org/dev/core/-/issues/4433)
The method
CRM_Utils_System::url($path, ...)
is used to construct the full URL for a route. On WordPress, it is important to determine whether the route is intended for frontend/public usage or backend/private usage. URLs may look like:We recently started to see failures in
E2E\Core\PathUrlTest::testGetUrl_WpAdmin()
, which asserts that a particular URL is backend/private.The proximate cause is that
cv url
changed to mirror the default fromCRM_Utils_System::url()
. IMHO, the root-cause is that the contract forCRM_Utils_System::url()
is confusing. This patch tries to make the contract easier.Of course, the fact that I am confused by the contract means that I may not fully understand. Hopefully @christianwach or @kcristiano understand WP URLs' better and can give some feedback.
Before
CRM_Utils_System::url()
accepts two optional parameters,bool $frontend=FALSE
andbool $forceBackend=FALSE
.Conceptually, the choice is binary - you either have a frontend URL or a backend URL. But the contract allows four choices (
FALSE,FALSE
andTRUE,FALSE
andFALSE,TRUE
andTRUE,TRUE
). It seems clear enough when you haveTRUE,FALSE
orFALSE,TRUE
-- but the meaning ofFALSE,FALSE
andTRUE,TRUE
seems ambiguous.Additionally, this seems related to -- but different from -- the property
civicrm_menu.is_public
. I can understand the cases where either:is_public=1
andurl()
is called with$frontend=TRUE
is_public=0
andurl()
is called with$forceBackend=TRUE
But the other possibilities (
is_public=1
with$forceBackend=TRUE
) seem confusing to me.After
CRM_Utils_System::url()
still accepts two optional parameters,bool $frontend=FALSE
andbool $forceBackend=FALSE
. (You can't remove them without a hard break.)In the default case (
FALSE,FALSE
) and in the other ambiguous case (TRUE,TRUE
), it will lookup the value ofis_public
and use that. For example:CRM_Utils_System::url('civicrm/contribute/transact', 'reset'=1)
==> Use the frontend URL (because the route specifiesis_public=1
and the caller hasn't indicated a clear preference).CRM_Utils_System::url('civicrm/contribute', 'reset'=1)
==> Use the backend URL (because the route specifiesis_public=0
and the caller hasn't indicated a clear preference)But if the caller does have a specific request (
TRUE,FALSE
orFALSE,TRUE
), then that is respected.On my local, this appears to fix
testGetUrl_WpAdmin()
.Comments
I don't understand everything in WP URL's, so hopefully folks with experience there.
I was concerned about possibility of performance impact -- e.g. you don't want
SELECT is_public FROM civicrm_menu
every time the system renders aurl()
. The approach in here should only require 1 moderate-sized cache-item (1-2 kb).There are some routes like
civicrm/ajax/api4/*
which are sort of fundamentally ambiguous -- they're headless, so calling them "frontend" or "backend" is sort of meaningless. Maybe that needs some kind ofr-run
to ensure that API4 REST calls work in both UIs?If this is all too aggressive, I could do a narrower fix in cv-only -- e.g. we retain the current contract for
CRM_Utils_System::url()
, and then updatecv url
to pick its default convention based onis_public
.