Before
In Drupal version prior to 8.5, the serialized File entity uri field value in HAL+JSON format contains the absolute URL only. You'd get something like:
{
'value' => 'https://example.com/sites/default/files/llama.jpg',
}
This is undesirable as it hard codes the host and schema (affecting cacheability), but also means we cannot ever get the actual value that has been saved (before being transformed to a full URL), hence making it very difficult to update File entities.
After
In Drupal 8.5, the original uri field value property is returned, as well as a new (computed) root-relative url property. This can be used to consume to actual file.
{
'value' => 'public://llama.jpg',
'url' => '/sites/default/files/llama.jpg',
}
Backwards compatible: existing sites can opt in to the old behavior
Existing sites can opt in to the new behavior by changing the bc_file_uri_as_url_normalizer key's value from true to false in hal.settings configuration using one of the following mechanisms:
- Use the Configuration API in custom module or integration code.
- Use Drush:
drush config-set hal.settings bc_file_uri_as_url_normalizer FALSE - Use configuration override
This backwards compatibility layer will be maintained until Drupal 9; in Drupal 9.0 it will be dropped.
Comments
Opting in/out confusion
The section "Backwards compatible: existing sites can opt in to the old behavior" starts with:
Either way, I can't seem to get this to work after upgrading from 8.4.
My error
I updated a different site to the one I was testing. That's bound to cause problems.