Commit 6df284ec authored by alexpott's avatar alexpott

Issue #2308187 by lauriii, iMiksu, joelpittet, dawehner, er.pushpinderrana:...

Issue #2308187 by lauriii, iMiksu, joelpittet, dawehner, er.pushpinderrana: Provide a twig extension for file_create_url
parent d3ccfcd5
......@@ -76,6 +76,7 @@ public function getFunctions() {
new \Twig_SimpleFunction('path', array($this, 'getPath'), array('is_safe_callback' => array($this, 'isUrlGenerationSafe'))),
new \Twig_SimpleFunction('url_from_path', array($this, 'getUrlFromPath'), array('is_safe_callback' => array($this, 'isUrlGenerationSafe'))),
new \Twig_SimpleFunction('link', array($this, 'getLink')),
new \Twig_SimpleFunction('file_url', 'file_create_url'),
);
}
......
......@@ -65,7 +65,7 @@ public function testTwigUrlGenerator() {
}
/**
* Tests the link_generator twig functions.
* Tests the link_generator Twig functions.
*/
public function testTwigLinkGenerator() {
$this->drupalGet('twig-theme-test/link-generator');
......@@ -83,4 +83,13 @@ public function testTwigLinkGenerator() {
}
}
/**
* Tests the file url Twig functions.
*/
public function testTwigFileUrls() {
$this->drupalGet('/twig-theme-test/file-url');
$filepath = file_create_url('core/modules/system/tests/modules/twig_theme_test/twig_theme_test.js');
$this->assertRaw('<div>file_url: ' . $filepath . '</div>');
}
}
......@@ -49,4 +49,13 @@ public function linkGeneratorRender() {
);
}
/**
* Renders for testing file_create_url functions in a Twig template.
*/
public function fileUrlRender() {
return array(
'#theme' => 'twig_theme_test_file_url',
);
}
}
<div>file_url: {{ file_url('core/modules/system/tests/modules/twig_theme_test/twig_theme_test.js') }}</div>
/* This file is for testing asset file inclusion, no contents are necessary. */
......@@ -33,6 +33,10 @@ function twig_theme_test_theme($existing, $type, $theme, $path) {
'variables' => array('test_url' => NULL),
'template' => 'twig_theme_test.link_generator',
);
$items['twig_theme_test_file_url'] = array(
'variables' => array(),
'template' => 'twig_theme_test.file_url',
);
return $items;
}
......
......@@ -25,3 +25,10 @@ twig_theme_test_link_generator:
_controller: '\Drupal\twig_theme_test\TwigThemeTestController::linkGeneratorRender'
requirements:
_access: 'TRUE'
twig_theme_test_file_url:
path: '/twig-theme-test/file-url'
defaults:
_controller: '\Drupal\twig_theme_test\TwigThemeTestController::fileUrlRender'
requirements:
_access: 'TRUE'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment