Skip to content

Commit 00bf336

Browse files
authored
Fix is default (#138)
1 parent 0489894 commit 00bf336

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

app/code/Magento/EavGraphQl/Model/Output/GetAttributeData.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function execute(
7070
*
7171
* @param AttributeInterface $attribute
7272
* @return string
73+
* @throws RuntimeException
7374
*/
7475
private function getFrontendInput(AttributeInterface $attribute): string
7576
{
@@ -108,11 +109,28 @@ function (AttributeOptionInterface $option) use ($attribute) {
108109
return [
109110
'label' => $label,
110111
'value' => $value,
111-
'is_default' => in_array($value, explode(',', $attribute->getDefaultValue()))
112+
'is_default' => $attribute->getDefaultValue() &&
113+
$this->isDefault($value, $attribute->getDefaultValue())
112114
];
113115
},
114116
$attribute->getOptions()
115117
)
116118
);
117119
}
120+
121+
/**
122+
* Returns true if $value is the default value. Otherwise, false.
123+
*
124+
* @param mixed $value
125+
* @param mixed $defaultValue
126+
* @return bool
127+
*/
128+
private function isDefault(mixed $value, mixed $defaultValue): bool
129+
{
130+
if (is_array($defaultValue)) {
131+
return in_array($value, $defaultValue);
132+
}
133+
134+
return in_array($value, explode(',', $defaultValue));
135+
}
118136
}

0 commit comments

Comments
 (0)