Skip to content
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

Allow most values of $civicrm_paths['XXX']['url'] to be relative #16403

Merged
merged 3 commits into from
Jan 30, 2020

Conversation

totten
Copy link
Member

@totten totten commented Jan 28, 2020

Overview

The $civicrm_paths variable allows a sysadmin to override various path and URL computations.

$civicrm_paths['civicrm.packages']['url'] = 'https://example.com/libraries/civicrm/packages';

These values are used to generate addresses, as in:

$abs = Civi::paths()->getUrl('[civicrm.packages]/foo.js', 'absolute');
$rel = Civi::paths()->getUrl('[civicrm.packages]/foo.js', 'relative');

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 that getUrl() 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.

$civicrm_paths['civicrm.packages']['url'] = 'https://example.com/libraries/civicrm/packages';
$civicrm_paths['civicrm.packages']['url'] = '/libraries/civicrm/packages';

Comments

  • This PR is an extracted subset of (WIP) Exploratory branch for composer/D8 builds #16328, which was an exploratory branch aimed at supporting deployment of Civi git repos in D8 via composer. The changes are extracted to make the size of the review more manageable. It's probably best to use this smaller PR to consider topics like regression-risk and general code convention rather than trying to assess the fuller aims of (WIP) Exploratory branch for composer/D8 builds #16328.
  • toAbsoluteUrl() needs a base to prepend. I initially used HTTP_HOST but switched to cms.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. Using cms.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.
  • It's tempting to allow recursive variables. But it's not actually needed for my purposes, and it would add complexity/maintenance. If it's really needed, one could add that at a later time. But for now... I think the simpler format is fine.

Overview
--------

The `$civicrm_paths` variable allows a sysadmin to override various path and
URL computations.

```php
$civicrm_paths['civicrm.packages']['url'] = 'https://example.com/libraries/civicrm/packages';
```

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/).

These values are used to generate addresses, as in:

```php
$abs = Civi::paths()->getUrl('[civicrm.packages]/foo.js', 'absolute');
$rel = Civi::paths()->getUrl('[civicrm.packages]/foo.js', 'relative');
```

The patch allows more values in `$civicrm_paths` while ensuring that
`getUrl()` 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.

```php
$civicrm_paths['civicrm.packages']['url'] = 'https://example.com/libraries/civicrm/packages';
$civicrm_paths['civicrm.packages']['url'] = '/libraries/civicrm/packages';
```

Comments
--------

* `toAbsoluteUrl()` needs a base to prepend. I initially used `HTTP_HOST`
  but switched to `cms.root`, but correctly inferring scheme and host and port
  and httpd prefixes would be more complex - esp for background/CLI jobs.
  Using `cms.root` as the base is simpler.
* It's tempting to allow recursive variables. But it's not actually needed for
  my purposes, and it would add complexity/maintenance. If it's really needed,
  one could update `toAbsoluteUrl()` to quickly check for variables
  (`$url[0] === '['`) and then evaluate them. But for now... I think the
  simpler format is fine.
1. The expected value of `$civicrmBaseUrl` should not be blank. The old value was a fiction of
   the unit-test environment. Be more realistic.
2. The expected values for extension-generated URLs should abide the same `$civicrmBaseUrl` as others.
This will allow E2E matrix to send a signal about whether the default
configurations produce valid URLs.
@civibot
Copy link

civibot bot commented Jan 28, 2020

(Standard links)

@civibot civibot bot added the master label Jan 28, 2020
@eileenmcnaughton
Copy link
Contributor

It's mostly tests!

new function is well tested & only used in edge cases - merging

@eileenmcnaughton eileenmcnaughton merged commit a092d58 into civicrm:master Jan 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants