forked from ilrWebServices/union
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalter-twig.php
More file actions
49 lines (40 loc) · 1.25 KB
/
alter-twig.php
File metadata and controls
49 lines (40 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
require __DIR__ . '/vendor/autoload.php';
use \Drupal\Core\Template\Attribute;
/**
* @param Twig_Environment $env - The Twig Environment - https://twig.symfony.com/api/1.x/Twig_Environment.html
* @param $config - Config of `@basalt/twig-renderer`
*/
function addCustomExtension(\Twig_Environment &$env, $config) {
/**
* Adds the dump() function and other debug functionality.
*/
$env->addExtension(new \Twig_Extension_Debug());
/**
* Add the custom union_attributes function.
*/
$env->addFunction(new \Twig_SimpleFunction('union_attributes', function($attributes) {
return is_array($attributes) ? new Attribute($attributes) : $attributes;
}));
/**
* Add the custom union_file function.
*
* @todo Implement this for patternlab integration.
*/
$env->addFunction(new \Twig_SimpleFunction('union_file', function($filepath) {
return '../..' . $filepath;
}));
/**
* Stub attach_library to prevent PL errors.
*/
$env->addFunction(new Twig_SimpleFunction('attach_library', function($string) {
return '';
}));
/**
* Return a digest for a given string.
*
* @param string $string
* @return string sha1 hash of $string
*/
$env->addFunction(new Twig_SimpleFunction('union_digest', 'sha1'));
}