Files.php in Bamboo Twig 8
File
bamboo_twig_files/src/TwigExtension/Files.php
View source
<?php
namespace Drupal\bamboo_twig_files\TwigExtension;
use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser;
class Files extends \Twig_Extension {
public function getFunctions() {
return [
new \Twig_SimpleFunction('theme_url', [
$this,
'themeUrl',
], [
'is_safe' => [
'html',
],
]),
];
}
public function getFilters() {
return [
new \Twig_SimpleFilter('extension_guesser', [
$this,
'extensionGuesser',
]),
];
}
public function getName() {
return 'bamboo_twig.twig.files';
}
public static function extensionGuesser($mime_type) {
$guesser = ExtensionGuesser::getInstance();
return $guesser
->guess($mime_type);
}
public static function themeUrl($theme, $file) {
return file_create_url(drupal_get_path('theme', $theme) . '/' . $file);
}
}
Classes
Name |
Description |
Files |
Provides a 'Files' Twig Extensions. |