From 2ba30f2eae351e2011d9f2521d950ab9fdbac5ed Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Wed, 15 May 2024 16:34:06 +0100 Subject: [PATCH] Ensure default config values are available in form tag --- src/Fields/Fieldtype.php | 9 +++++++++ src/Tags/Concerns/RendersForms.php | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Fields/Fieldtype.php b/src/Fields/Fieldtype.php index 9c1bca046a..12ff2f0e6a 100644 --- a/src/Fields/Fieldtype.php +++ b/src/Fields/Fieldtype.php @@ -253,6 +253,15 @@ public function configFields(): Fields return new ConfigFields($fields); } + public function defaultConfigValues(): array + { + return Field::commonFieldOptions()->all() + ->merge($this->configFields()->all()) + ->filter(fn (ConfigField $configField) => $configField->get('default')) + ->map(fn (ConfigField $configField) => $configField->get('default')) + ->all(); + } + protected function configFieldItems(): array { return $this->configFields; diff --git a/src/Tags/Concerns/RendersForms.php b/src/Tags/Concerns/RendersForms.php index f80ba5c479..1ffcf28c04 100644 --- a/src/Tags/Concerns/RendersForms.php +++ b/src/Tags/Concerns/RendersForms.php @@ -135,7 +135,7 @@ protected function getRenderableField($field, $errorBag = 'default', $manipulate $default = $field->value() ?? $field->defaultValue(); $value = $old === $missing ? $default : $old; - $data = array_merge($field->toArray(), [ + $data = array_merge($field->fieldtype()->defaultConfigValues(), $field->toArray(), [ 'instructions' => $field->instructions(), 'error' => $errors->first($field->handle()) ?: null, 'default' => $field->value() ?? $field->defaultValue(),