-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAttributeExtension.php
More file actions
35 lines (30 loc) · 859 Bytes
/
Copy pathAttributeExtension.php
File metadata and controls
35 lines (30 loc) · 859 Bytes
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
<?php
declare(strict_types=1);
namespace Parisek\Twig;
use Drupal\Component\Attribute\AttributeCollection;
use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
final class AttributeExtension extends AbstractExtension
{
public function getFunctions(): array
{
return [
new TwigFunction(
'create_attribute',
[$this, 'createAttribute'],
[
'needs_environment' => true,
'is_safe' => ['html'],
],
),
];
}
/**
* @param array<string, mixed> $attributes Attribute name => value pairs.
*/
public function createAttribute(Environment $environment, array $attributes = []): AttributeCollection
{
return new AttributeCollection($attributes);
}
}