You are here

function file_url_transform_relative in Drupal 9

Same name and namespace in other branches
  1. 8 core/includes/file.inc \file_url_transform_relative()

Transforms an absolute URL of a local file to a relative URL.

May be useful to prevent problems on multisite set-ups and prevent mixed content errors when using HTTPS + HTTP.

Parameters

string $file_url: A file URL of a local file as generated by FileUrlGeneratorInterface::generateString().

Return value

string If the file URL indeed pointed to a local file and was indeed absolute, then the transformed, relative URL to the local file. Otherwise: the original value of $file_url.

Deprecated

in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\Core\File\FileUrlGenerator::transformRelative() instead.

See also

https://www.drupal.org/node/2940031

\Drupal\Core\File\FileUrlGeneratorInterface::transformRelative()

Related topics

1 call to file_url_transform_relative()
FileSystemDeprecationTest::testDeprecatedFileCreateUrl in core/tests/Drupal/KernelTests/Core/File/FileSystemDeprecationTest.php
Tests deprecated FileCreateUrl.

File

core/includes/file.inc, line 97
API for handling file uploads and server file management.

Code

function file_url_transform_relative($file_url) {
  @trigger_error('file_url_transform_relative() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \\Drupal\\Core\\File\\FileUrlGenerator::transformRelative() instead. See https://www.drupal.org/node/2940031', E_USER_DEPRECATED);
  return \Drupal::service('file_url_generator')
    ->transformRelative($file_url);
}