Commit 7594f7eb authored by alexpott's avatar alexpott

Issue #2416857 by cilefen, evgeny.chernyavskiy, lauriii, chr.fritsch,...

Issue #2416857 by cilefen, evgeny.chernyavskiy, lauriii, chr.fritsch, pjonckiere: Add an active_theme_path twig function
parent 5b8b5aad
......@@ -137,6 +137,7 @@ public function getFunctions() {
new \Twig_SimpleFunction('link', array($this, 'getLink')),
new \Twig_SimpleFunction('file_url', 'file_create_url'),
new \Twig_SimpleFunction('attach_library', [$this, 'attachLibrary']),
new \Twig_SimpleFunction('active_theme_path', [$this, 'getActiveThemePath']),
new \Twig_SimpleFunction('active_theme', [$this, 'getActiveTheme']),
];
}
......@@ -294,6 +295,16 @@ public function getActiveTheme() {
return $this->themeManager->getActiveTheme()->getName();
}
/**
* Gets the path of the active theme.
*
* @return string
* The path to the active theme.
*/
public function getActiveThemePath() {
return $this->themeManager->getActiveTheme()->getPath();
}
/**
* Determines at compile time whether the generated URL will be safe.
*
......
......@@ -125,6 +125,33 @@ public function testFormatDate() {
$this->assertEquals($date_formatter->format('html_date'), $result);
}
/**
* Tests the active_theme_path function.
*/
public function testActiveThemePath() {
$renderer = $this->getMock('\Drupal\Core\Render\RendererInterface');
$extension = new TwigExtension($renderer);
$theme_manager = $this->getMock('\Drupal\Core\Theme\ThemeManagerInterface');
$active_theme = $this->getMockBuilder('\Drupal\Core\Theme\ActiveTheme')
->disableOriginalConstructor()
->getMock();
$active_theme
->expects($this->once())
->method('getPath')
->willReturn('foo/bar');
$theme_manager
->expects($this->once())
->method('getActiveTheme')
->willReturn($active_theme);
$extension->setThemeManager($theme_manager);
$loader = new \Twig_Loader_String();
$twig = new \Twig_Environment($loader);
$twig->addExtension($extension);
$result = $twig->render('{{ active_theme_path() }}');
$this->assertEquals('foo/bar', $result);
}
/**
* Tests the escaping of objects implementing MarkupInterface.
*
......
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