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
7af29a9e52
commit
8d1c4c16d4
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue