class HelperExtension in Helper 8
Twig extension with some useful functions and filters.
Hierarchy
- class \Drupal\helper\Twig\HelperExtension extends \Drupal\helper\Twig\Twig_Extension
Expanded class hierarchy of HelperExtension
1 string reference to 'HelperExtension'
1 service uses HelperExtension
File
- src/
Twig/ HelperExtension.php, line 10
Namespace
Drupal\helper\TwigView source
class HelperExtension extends \Twig_Extension {
/**
* The file helper service.
*
* @var \Drupal\helper\File
*/
protected $fileHelper;
/**
* Constructs \Drupal\helper\Twig\HelperExtension.
*
* @param \Drupal\helper\File $file_helper
* The file helper.
*/
public function __construct(File $file_helper) {
$this->fileHelper = $file_helper;
}
/**
* {@inheritdoc}
*/
public function getFunctions() {
return [
new \Twig_SimpleFunction('file_data_uri', [
$this,
'fileDataUri',
]),
];
}
/**
* {@inheritdoc}
*/
public function getName() {
return 'drupal_helper';
}
/**
* Converts a file URL into a data URI.
*
* @param string $uri
* The file URI.
* @param bool $base_64_encode
* TRUE to return the data URI as base-64 encoded content.
* @param string|null $mimetype
* The optional mime type to provide for the data URI. If not provided
* the mime type guesser service will be used.
*
* @return string
* The image data URI for use in a src attribute.
*/
public function fileDataUri($uri, $base_64_encode = TRUE, $mimetype = NULL) {
return $this->fileHelper
->getDataUri($uri, $base_64_encode, $mimetype);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
HelperExtension:: |
protected | property | The file helper service. | |
HelperExtension:: |
public | function | Converts a file URL into a data URI. | |
HelperExtension:: |
public | function | ||
HelperExtension:: |
public | function | ||
HelperExtension:: |
public | function | Constructs \Drupal\helper\Twig\HelperExtension. |