|
|
@ -110,6 +110,7 @@ class TwigTweakExtension extends AbstractExtension { |
|
|
|
new TwigFilter('truncate', [Unicode::class, 'truncate']), |
|
|
|
new TwigFilter('truncate', [Unicode::class, 'truncate']), |
|
|
|
new TwigFilter('view', [self::class, 'viewFilter']), |
|
|
|
new TwigFilter('view', [self::class, 'viewFilter']), |
|
|
|
new TwigFilter('with', [self::class, 'withFilter']), |
|
|
|
new TwigFilter('with', [self::class, 'withFilter']), |
|
|
|
|
|
|
|
new TwigFilter('data_uri', [self::class, 'dataUriFilter']), |
|
|
|
new TwigFilter('children', [self::class, 'childrenFilter']), |
|
|
|
new TwigFilter('children', [self::class, 'childrenFilter']), |
|
|
|
new TwigFilter('file_uri', [self::class, 'fileUriFilter']), |
|
|
|
new TwigFilter('file_uri', [self::class, 'fileUriFilter']), |
|
|
|
new TwigFilter('file_url', [self::class, 'fileUrlFilter']), |
|
|
|
new TwigFilter('file_url', [self::class, 'fileUrlFilter']), |
|
|
@ -570,6 +571,19 @@ class TwigTweakExtension extends AbstractExtension { |
|
|
|
return $build; |
|
|
|
return $build; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Creates a data URI (RFC 2397). |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static function dataUriFilter(string $data, string $mime, array $parameters = []): string { |
|
|
|
|
|
|
|
$uri = 'data:' . $mime; |
|
|
|
|
|
|
|
foreach ($parameters as $key => $value) { |
|
|
|
|
|
|
|
$uri .= ';' . $key . '=' . rawurlencode($value); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$uri .= \str_starts_with($data, 'text/') ? |
|
|
|
|
|
|
|
',' . rawurlencode($data) : ';base64,' . base64_encode($data); |
|
|
|
|
|
|
|
return $uri; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Adds new element to the array. |
|
|
|
* Adds new element to the array. |
|
|
|
* |
|
|
|
* |
|
|
|