feat(18-04): settings forms take method-backed dropdown options from the settings model (task 1)
- the settings schema passes the settings model as the DropdownOptionsProvider - boot refuses a dropdown method on a settings model without DropdownOptions - cabana README and docs/backend/settings.md describe it
This commit is contained in:
@@ -108,6 +108,11 @@ func compileSettingWithTypes(pluginID string, item pact.SettingsItem, fsys fs.FS
|
||||
if err := settingsFormOnly(field); err != nil {
|
||||
return nil, fmt.Errorf("cabana: setting %s field %s: %w", item.Code, field.Name, err)
|
||||
}
|
||||
// A method-backed dropdown takes its options from the settings model,
|
||||
// as a relation form takes them from its related model.
|
||||
if field.optionsMethod != "" && modelDropdownProvider(model) == nil {
|
||||
return nil, fmt.Errorf("cabana: setting %s field %s: dropdown method %s requires DropdownOptions on the settings model", item.Code, field.Name, field.optionsMethod)
|
||||
}
|
||||
}
|
||||
form := &FormSchema{Name: item.Label, ModelClass: item.Model, Fields: fields}
|
||||
columns := modelColumns(model)
|
||||
@@ -151,6 +156,16 @@ func compileSettingWithTypes(pluginID string, item pact.SettingsItem, fsys fs.FS
|
||||
return &CompiledSetting{PluginID: pluginID, Item: item, Form: form, Writable: writable, Secrets: secrets}, nil
|
||||
}
|
||||
|
||||
// settingDropdownProvider is the settings model of setting as the provider
|
||||
// of its method-backed dropdown options, or nil.
|
||||
func settingDropdownProvider(setting *CompiledSetting) pact.DropdownOptionsProvider {
|
||||
model, err := newSettingModel(setting)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return modelDropdownProvider(model)
|
||||
}
|
||||
|
||||
// Get returns default-valued data without creating a missing singleton.
|
||||
func (s SettingsService) Get(ctx context.Context, setting *CompiledSetting) (SettingsResult, error) {
|
||||
if s.DB == nil {
|
||||
|
||||
Reference in New Issue
Block a user