Skip to content

Commit a6ba72d

Browse files
pavlosdanfubhy
authored andcommitted
Check for link attributes that are arrays and implode them. (#687)
1 parent 46e0bc6 commit a6ba72d

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

modules/graphql_core/src/Plugin/GraphQL/Fields/Entity/Fields/Link/LinkAttribute.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ class LinkAttribute extends FieldPluginBase {
3131
protected function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) {
3232
if ($value instanceof LinkItemInterface) {
3333
$options = $value->getUrl()->getOptions();
34-
yield NestedArray::getValue($options, ['attributes', $args['key']]);
34+
35+
// Certain attributes like class can be arrays. Check for that and implode them.
36+
$attributeValue = NestedArray::getValue($options, ['attributes', $args['key']]);
37+
if (is_array($attributeValue)) {
38+
yield implode(' ', $attributeValue);
39+
} else {
40+
yield $attributeValue;
41+
}
3542
}
3643
}
3744

modules/graphql_core/src/Plugin/GraphQL/Fields/MenuLink/MenuLinkAttribute.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ class MenuLinkAttribute extends FieldPluginBase {
3030
protected function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) {
3131
if ($value instanceof MenuLinkTreeElement) {
3232
$options = $value->link->getOptions();
33-
yield NestedArray::getValue($options, ['attributes', $args['key']]);
33+
34+
// Certain attributes like class can be arrays. Check for that and implode them.
35+
$attributeValue = NestedArray::getValue($options, ['attributes', $args['key']]);
36+
if (is_array($attributeValue)) {
37+
yield implode(' ', $attributeValue);
38+
} else {
39+
yield $attributeValue;
40+
}
3441
}
3542
}
3643

0 commit comments

Comments
 (0)