Skip to content

Commit aa01193

Browse files
committed
Give custom fields priority
1 parent c05e536 commit aa01193

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/Concerns/CanMapDynamicFields.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ protected function mutateBeforeSave(array $data): array
8787

8888
private function resolveFieldConfigAndInstance(Model $field): array
8989
{
90-
$fieldConfig = Field::tryFrom($field->field_type)
91-
? $this->fieldInspector->initializeDefaultField($field->field_type)
92-
: $this->fieldInspector->initializeCustomField($field->field_type);
90+
// Try to resolve from custom fields first
91+
$fieldConfig = Fields::resolveField($field->field_type) ?
92+
$this->fieldInspector->initializeCustomField($field->field_type) :
93+
$this->fieldInspector->initializeDefaultField($field->field_type);
94+
9395

9496
return [
9597
'config' => $fieldConfig,
@@ -150,7 +152,7 @@ private function resolveFieldInput(Model $field, Collection $customFields, mixed
150152
return $customField::make($inputName, $field);
151153
}
152154

153-
// Fall back to standard field type map if no custom field found
155+
// // Fall back to standard field type map if no custom field found
154156
if ($fieldClass = self::FIELD_TYPE_MAP[$field->field_type] ?? null) {
155157
return $fieldClass::make(name: $inputName, field: $field);
156158
}

src/Concerns/HasFieldTypeResolver.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ protected function getFieldTypeFormSchema(?string $fieldType): array
3131

3232
protected static function resolveFieldTypeClassName(string $fieldType): ?string
3333
{
34+
if (isset(Fields::getFields()[$fieldType])) {
35+
return Fields::getFields()[$fieldType];
36+
}
37+
3438
if (Field::tryFrom($fieldType)) {
3539
return sprintf('Backstage\\Fields\\Fields\\%s', Str::studly($fieldType));
3640
}
3741

38-
return Fields::getFields()[$fieldType] ?? null;
42+
return null;
3943
}
4044

4145
protected function isValidFieldClass(?string $className): bool

0 commit comments

Comments
 (0)