Skip to content

HelperExtension

Twig extension with some useful functions and filters.


  • Full name: \Drupal\helper\Twig\HelperExtension
  • Parent class: AbstractExtension
  • This class implements: LoggerAwareInterface

Properties

fileHelper

protected ?\Drupal\helper\File $fileHelper

Methods

__construct

Constructs \Drupal\helper\Twig\HelperExtension.

public __construct(\Drupal\helper\File|null $fileHelper = null): mixed

Parameters:

Parameter Type Description
$fileHelper \Drupal\helper\File|null
The file helper, or NULL when the file module isn't installed, such as
in kernel tests that don't enable it.

getFunctions

{@inheritdoc}

public getFunctions(): array

getFilters

{@inheritdoc}

public getFilters(): array

getName

{@inheritdoc}

public getName(): mixed

fileDataUri

Converts a file URL into a data URI.

public fileDataUri(string $uri, bool $base_64_encode = true, string|null $mimetype = null): string

Parameters:

Parameter Type Description
$uri string
The file URI.
$base_64_encode bool
TRUE to return the data URI as base-64 encoded content.
$mimetype string|null
The optional mime type to provide for the data URI. If not provided
the mime type guesser service will be used.

Return Value:

The image data URI for use in a src attribute, or an empty string if the file can't be read or the file module isn't installed.