Skip to content

Commit

Permalink
Ensure default config values are available in form tag
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed May 15, 2024
1 parent 4bbd23e commit 2ba30f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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

0 comments on commit 2ba30f2

Please sign in to comment.