Skip to content

Commit 4be2922

Browse files
author
Marc Berger
committed
fix: Importing fix from PR-61 emulsify_twig
1 parent 28d42db commit 4be2922

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/AddAttributesTwigExtension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public function getFunctions() {
3232
public function addAttributes($context, $additional_attributes = []) {
3333
$attributes = new Attribute();
3434

35+
// If context attributes doesn't exist or is an array, create new Attribute.
36+
$context['attributes'] = $context['attributes'] ?? new Attribute();
37+
if (is_array($context['attributes'])) {
38+
$context['attributes'] = new Attribute($context['attributes']);
39+
}
40+
3541
if (!empty($additional_attributes)) {
3642
foreach ($additional_attributes as $key => $value) {
3743

src/BemTwigExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ public function bem($context, $base_class, $modifiers = [], $blockname = '', $ex
101101
}
102102
if (class_exists('Drupal')) {
103103
$attributes = new Attribute();
104+
105+
// If context attributes doesn't exist or is an array, create new Attribute.
106+
$context['attributes'] = $context['attributes'] ?? new Attribute();
107+
if (is_array($context['attributes'])) {
108+
$context['attributes'] = new Attribute($context['attributes']);
109+
}
110+
104111
// Checking the attributes from the context.
105112
if (!empty($context['attributes'])) {
106113
// Iterate the attributes available in context.

0 commit comments

Comments
 (0)