Commit d6e4a299 authored by catch's avatar catch
Browse files

Issue #3223016 by kim.pepper, Berdir, andypost, daffie: Deprecate file_build_uri()

parent e41394ec
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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');
+4 −1
Original line number Diff line number Diff line
@@ -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)];
    }

+3 −1
Original line number Diff line number Diff line
@@ -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))) {
+8 −0
Original line number Diff line number Diff line
@@ -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'));
  }

}
+1 −5
Original line number Diff line number Diff line
@@ -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