Commit d60ba4d8 authored by catch's avatar catch
Browse files

Issue #3254727 by Leon Kessler, ranjith_kumar_k_u, cmlara, andileco: File...

Issue #3254727 by Leon Kessler, ranjith_kumar_k_u, cmlara, andileco: File links with query parameters no longer work
parent e5c38d9e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1522,7 +1522,7 @@ function template_preprocess_file_link(&$variables) {
  $variables['attributes']->addClass($classes);
  $variables['file_size'] = format_size($file->getSize() ?? 0);

  $variables['link'] = Link::fromTextAndUrl($link_text, $url->setOptions($options))->toRenderable();
  $variables['link'] = Link::fromTextAndUrl($link_text, $url->mergeOptions($options))->toRenderable();
}

/**
+19 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ class FileEntityFormatterTest extends KernelTestBase {
  /**
   * {@inheritdoc}
   */
  protected static $modules = ['file', 'user'];
  protected static $modules = ['file', 'user', 'file_test'];

  /**
   * The files.
@@ -171,4 +171,22 @@ public function testFormatterFileSize() {
    }
  }

  /**
   * Tests the file_link field formatter using a query string.
   */
  public function testFormatterFileLinkWithQueryString() {
    $file = File::create([
      'uri' => 'dummy-external-readonly://file-query-string?foo=bar',
      'filename' => 'file-query-string',
    ]);
    $file->save();
    $file_link = [
      '#theme' => 'file_link',
      '#file' => $file,
    ];

    $output = \Drupal::service('renderer')->renderRoot($file_link);
    $this->assertStringContainsString($this->fileUrlGenerator->generate('dummy-external-readonly://file-query-string?foo=bar')->toUriString(), $output);
  }

}