Allow most values of $civicrm_paths['XXX']['url'] to be relative #16403
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
The
$civicrm_paths
variable allows a sysadmin to override various path and URL computations.These values are used to generate addresses, as in:
The variable was originally tested with absolute URLs, and the subsequent examples/docs use absolute URLs (https://docs.civicrm.org/dev/en/latest/framework/filesystem/).
The patch allows more values in
$civicrm_paths
while ensuring thatgetUrl()
works as expected.Before
The
getUrl()
requests only behave correctly if the override is an absolute URL - not if it's relative.After
The
getUrl()
requests behave correctly if the override is either an absolute URL or a relative URL.Comments
toAbsoluteUrl()
needs a base to prepend. I initially usedHTTP_HOST
but switched tocms.root
. Why? Correctly inferring scheme and host and port and path prefixes would be more complex - esp when you consider background/CLI jobs and firewalls/proxies. Usingcms.root
as the base is simpler. This leaves us with a limitation -- if one were to override$civicrm_packages['cms.root']['url']
, then that one would still need to be an absolute URL. However, that's no worse than today and doesn't impede my use-case.