Skip to content

Commit 0ff521f

Browse files
authored
Merge pull request #24 from SteVO36/master
Fix incorrect caching of type InputfieldSelect and InputfieldSelectMultiple
2 parents 558f3df + 45b7769 commit 0ff521f

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/Type/Fieldtype/FieldtypeOptions.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use GraphQL\Type\Definition\ObjectType;
66
use ProcessWire\GraphQL\Cache;
77
use ProcessWire\InputfieldSelectMultiple;
8+
use ProcessWire\Field;
9+
use ProcessWire\GraphQL\Utils;
810
use ProcessWire\GraphQL\Type\Fieldtype\Traits\SetValueTrait;
911
use ProcessWire\GraphQL\Type\Fieldtype\Traits\FieldTrait;
1012

@@ -21,8 +23,8 @@ class FieldtypeOptions
2123

2224
public static function type($field)
2325
{
24-
return Cache::type(self::$name, function () use ($field) {
25-
$type = new ObjectType([
26+
$type = Cache::type(self::$name, function () use ($field) {
27+
return new ObjectType([
2628
'name' => self::$name,
2729
'description' => self::$description,
2830
'fields' => [
@@ -52,18 +54,18 @@ public static function type($field)
5254
]
5355
],
5456
]);
57+
});
5558

56-
if (self::isMultiple($field)) {
57-
return Type::listOf($type);
58-
}
59+
if (self::isMultiple($field)) {
60+
return Type::listOf($type);
61+
}
5962

60-
return $type;
61-
});
63+
return $type;
6264
}
6365

6466
public static function inputType($field)
6567
{
66-
return Cache::type(self::$inputName, function () use ($field) {
68+
return Cache::type(self::getName($field), function () use ($field) {
6769
$options = [];
6870
foreach ($field->type->getOptions($field) as $option) {
6971
$options[$option->title ? $option->title : $option->value] = [
@@ -73,7 +75,7 @@ public static function inputType($field)
7375
}
7476

7577
$type = new EnumType([
76-
'name' => self::$inputName,
78+
'name' => self::getName($field),
7779
'description' => "Possible values for the ". self::$name .".",
7880
'values' => $options,
7981
]);
@@ -110,4 +112,13 @@ public static function inputField($field)
110112
];
111113
});
112114
}
115+
116+
public static function getName(Field $field = null)
117+
{
118+
if ($field instanceof Field) {
119+
return Utils::normalizeTypeName("{$field->name}".self::$inputName);
120+
}
121+
122+
return self::$inputName;
123+
}
113124
}

0 commit comments

Comments
 (0)