Issue #3254245 by kim.pepper, Jeya sundhar, mrweiner, bakulahluwalia, Berdir, catch, newaytech, Summit: TypeError: Argument 1 passed to Drupal\Core\File\FileUrlGenerator::generateString() must be of the type string, null given
parent
3c6394a483
commit
9d3bdf2b4a
|
@ -65,6 +65,9 @@ const FILE_STATUS_PERMANENT = 1;
|
|||
*/
|
||||
function file_create_url($uri) {
|
||||
@trigger_error('file_create_url() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use the appropriate method on \Drupal\Core\File\FileUrlGeneratorInterface instead. See https://www.drupal.org/node/2940031', E_USER_DEPRECATED);
|
||||
if (is_null($uri)) {
|
||||
return NULL;
|
||||
}
|
||||
try {
|
||||
return \Drupal::service('file_url_generator')->generateAbsoluteString($uri);
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ class TwigExtension extends AbstractExtension {
|
|||
new TwigFunction('url', [$this, 'getUrl'], ['is_safe_callback' => [$this, 'isUrlGenerationSafe']]),
|
||||
new TwigFunction('path', [$this, 'getPath'], ['is_safe_callback' => [$this, 'isUrlGenerationSafe']]),
|
||||
new TwigFunction('link', [$this, 'getLink']),
|
||||
new TwigFunction('file_url', [$this->fileUrlGenerator, 'generateString']),
|
||||
new TwigFunction('file_url', [$this, 'getFileUrl']),
|
||||
new TwigFunction('attach_library', [$this, 'attachLibrary']),
|
||||
new TwigFunction('active_theme_path', [$this, 'getActiveThemePath']),
|
||||
new TwigFunction('active_theme', [$this, 'getActiveTheme']),
|
||||
|
@ -272,6 +272,22 @@ class TwigExtension extends AbstractExtension {
|
|||
return $build;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the file URL.
|
||||
*
|
||||
* @param string|null $uri
|
||||
* The file URI.
|
||||
*
|
||||
* @return string
|
||||
* The file URL.
|
||||
*/
|
||||
public function getFileUrl(?string $uri) {
|
||||
if (is_null($uri)) {
|
||||
return NULL;
|
||||
}
|
||||
return $this->fileUrlGenerator->generateString($uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the active theme.
|
||||
*
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
<div>file_url: {{ file_url('core/modules/system/tests/modules/twig_theme_test/twig_theme_test.js') }}</div>
|
||||
<div>file_url: {{ file_url(undefined_variable) }}</div>
|
||||
|
|
|
@ -21,6 +21,7 @@ class FileSystemDeprecationTest extends KernelTestBase {
|
|||
$filepath = 'core/assets/vendor/jquery/jquery.min.js';
|
||||
$url = file_url_transform_relative(file_create_url($filepath));
|
||||
$this->assertNotEmpty($url);
|
||||
$this->assertEquals(NULL, file_create_url(NULL));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue