diff --git a/core/includes/file.inc b/core/includes/file.inc index 83812983a32382f717ac86bb5fb3d7f021634ffe..44a3cc3343cf24d1f23c9c2a660642e0a34b8a2f 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -95,8 +95,14 @@ function file_url_transform_relative($file_url) { /** * Constructs a URI to Drupal's default files location given a relative path. + * + * @deprecated in drupal:9.3.0 and is removed from drupal:10.0.0 without + * replacement. + * + * @see https://www.drupal.org/node/3223091 */ function file_build_uri($path) { + @trigger_error('file_build_uri() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0 without replacement. See https://www.drupal.org/node/3223091', E_USER_DEPRECATED); $uri = \Drupal::config('system.file')->get('default_scheme') . '://' . $path; /** @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager */ $stream_wrapper_manager = \Drupal::service('stream_wrapper_manager'); diff --git a/core/modules/image/src/Entity/ImageStyle.php b/core/modules/image/src/Entity/ImageStyle.php index 17d6f751a05b84840d15c13cd7ed9b16810e7473..f7edba286b088452af0d545dd5ea7ca2f3e573cb 100644 --- a/core/modules/image/src/Entity/ImageStyle.php +++ b/core/modules/image/src/Entity/ImageStyle.php @@ -222,7 +222,10 @@ public function buildUrl($path, $clean_urls = NULL) { $token_query = []; if (!\Drupal::config('image.settings')->get('suppress_itok_output')) { // The passed $path variable can be either a relative path or a full URI. - $original_uri = $stream_wrapper_manager::getScheme($path) ? $stream_wrapper_manager->normalizeUri($path) : file_build_uri($path); + if (!$stream_wrapper_manager::getScheme($path)) { + $path = \Drupal::config('system.file')->get('default_scheme') . '://' . $path; + } + $original_uri = $stream_wrapper_manager->normalizeUri($path); $token_query = [IMAGE_DERIVATIVE_TOKEN => $this->getPathToken($original_uri)]; } diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 8f4116503e27a07f517ae75b9143187318fd2b39..0edbe43b77091120dcdf5d62e1f68d5ccba4ea64 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1175,7 +1175,9 @@ function system_retrieve_file($url, $destination = NULL, $managed = FALSE, $repl /** @var \Drupal\Core\File\FileSystemInterface $file_system */ $file_system = \Drupal::service('file_system'); if (!isset($destination)) { - $path = file_build_uri(\Drupal::service('file_system')->basename($parsed_url['path'])); + $path = $file_system->basename($parsed_url['path']); + $path = \Drupal::config('system.file')->get('default_scheme') . '://' . $path; + $path = \Drupal::service('stream_wrapper_manager')->normalizeUri($path); } else { if (is_dir($file_system->realpath($destination))) { diff --git a/core/tests/Drupal/KernelTests/Core/File/FileSystemDeprecationTest.php b/core/tests/Drupal/KernelTests/Core/File/FileSystemDeprecationTest.php index c383b0ab59242dadd2fa35b6cb42fd2ce1ed0cf1..6d3eb63c8410706bfe5e0b9ce7f2e078af0dac79 100644 --- a/core/tests/Drupal/KernelTests/Core/File/FileSystemDeprecationTest.php +++ b/core/tests/Drupal/KernelTests/Core/File/FileSystemDeprecationTest.php @@ -23,4 +23,12 @@ public function testDeprecatedFileCreateUrl() { $this->assertNotEmpty($url); } + /** + * Tests deprecated file_build_uri() + */ + public function testDeprecatedFileBuildUri() { + $this->expectDeprecation('file_build_uri() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0 without replacement. See https://www.drupal.org/node/3223091'); + $this->assertEquals('public://foo/bar.txt', file_build_uri('foo/bar.txt')); + } + } diff --git a/core/tests/Drupal/KernelTests/Core/File/StreamWrapperTest.php b/core/tests/Drupal/KernelTests/Core/File/StreamWrapperTest.php index 6576c72c06077741c2f31332d2d7a394a7dc20f4..6aa2bdbec8d122849f6aeeedccab94d71f6c10af 100644 --- a/core/tests/Drupal/KernelTests/Core/File/StreamWrapperTest.php +++ b/core/tests/Drupal/KernelTests/Core/File/StreamWrapperTest.php @@ -89,15 +89,11 @@ public function testUriFunctions() { $this->assertSame($stream_wrapper_manager::getTarget('public://'), ''); $this->assertSame($stream_wrapper_manager::getTarget('data:'), ''); - // Test file_build_uri() and - // Drupal\Core\StreamWrapper\LocalStream::getDirectoryPath(). - $this->assertEquals('public://foo/bar.txt', file_build_uri('foo/bar.txt'), 'Expected scheme was added.'); + // Test Drupal\Core\StreamWrapper\LocalStream::getDirectoryPath(). $this->assertEquals(PublicStream::basePath(), $stream_wrapper_manager->getViaScheme('public')->getDirectoryPath(), 'Expected default directory path was returned.'); $file_system = \Drupal::service('file_system'); assert($file_system instanceof FileSystemInterface); $this->assertEquals($file_system->getTempDirectory(), $stream_wrapper_manager->getViaScheme('temporary')->getDirectoryPath(), 'Expected temporary directory path was returned.'); - $config->set('default_scheme', 'private')->save(); - $this->assertEquals('private://foo/bar.txt', file_build_uri('foo/bar.txt'), 'Got a valid URI from foo/bar.txt.'); // Test FileUrlGeneratorInterface::generateString() // TemporaryStream::getExternalUrl() uses Url::fromRoute(), which needs