Change record status: 
Project: 
Introduced in branch: 
8.5.x
Introduced in version: 
8.5.x
Description: 

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:

  1. Use the Configuration API in custom module or integration code.
  2. Use Drush: drush config-set hal.settings bc_file_uri_as_url_normalizer FALSE
  3. Use configuration override

This backwards compatibility layer will be maintained until Drupal 9; in Drupal 9.0 it will be dropped.

Impacts: 
Site builders, administrators, editors
Module developers
Themers

Comments

imclean’s picture

The section "Backwards compatible: existing sites can opt in to the old behavior" starts with:

Existing sites can opt in to the new behavior...

Either way, I can't seem to get this to work after upgrading from 8.4.

$config['hal.settings']['bc_file_uri_as_url_normalizer'] = FALSE;
imclean’s picture

I updated a different site to the one I was testing. That's bound to cause problems.