Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Ensure default config values are available in form tag #10088

Merged
merged 9 commits into from
May 15, 2024
9 changes: 9 additions & 0 deletions src/Fields/Fieldtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Tags/Concerns/RendersForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading