Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
admpub committed Oct 2, 2022
1 parent cb93876 commit 0d4b640
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,9 @@ func (c *Config) SetDefaultValue(fieldDefaultValue func(fieldName string) string
setDefaultValue(c.Elements, c.Languages, fieldDefaultValue)
}
}

func (c *Config) SetValue(fieldValue func(fieldName string) string) {
if fieldValue != nil {
setValue(c.Elements, c.Languages, fieldValue)
}
}
22 changes: 22 additions & 0 deletions config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,25 @@ func setDefaultValue(elements []*Element, languages []*Language, fieldDefaultVal
}
}
}

func setValue(elements []*Element, languages []*Language, fieldValue func(string) string) {
for _, elem := range elements {
if elem.Type == `langset` {
setValue(elem.Elements, elem.Languages, fieldValue)
continue
}
if elem.Type == `fieldset` {
setValue(elem.Elements, languages, fieldValue)
continue
}
if len(elem.Name) > 0 {
if len(languages) == 0 {
elem.Value = fieldValue(elem.Name)
continue
}
for _, lang := range languages {
elem.Value = fieldValue(lang.Name(elem.Name))
}
}
}
}

0 comments on commit 0d4b640

Please sign in to comment.