feat(cabana): add mltextarea field type
- mltextarea compiles (with size), binds as a writable scalar and goes through the mltext lift, translation write and hydrate paths - preset on or from an mltextarea field stays refused - tests: compile, Postgres round trip over a nullable host column with multi-line text, invalid locale maps, preset refusals
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
const (
|
||||
mlTextFieldType = "mltext"
|
||||
mlTextareaFieldType = "mltextarea"
|
||||
mlMarkdownFieldType = "mlmarkdown"
|
||||
)
|
||||
|
||||
@@ -41,11 +42,17 @@ type mlValue struct {
|
||||
values map[string]string
|
||||
}
|
||||
|
||||
// mlFieldType reports whether typ is a multilingual field type whose value is
|
||||
// a locale map: mltext, mltextarea or mlmarkdown.
|
||||
func mlFieldType(typ string) bool {
|
||||
return typ == mlTextFieldType || typ == mlMarkdownFieldType
|
||||
switch typ {
|
||||
case mlTextFieldType, mlTextareaFieldType, mlMarkdownFieldType:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// liftMLValues takes declared mltext/mlmarkdown maps out of a save body
|
||||
// liftMLValues takes declared mltext/mltextarea/mlmarkdown maps out of a save body
|
||||
// before ProjectWritableFields drops nested values. Only fields present in
|
||||
// the body whose context allows op are lifted. A value must be a JSON object
|
||||
// of enabled locale code to string; unknown locales, extra keys, and
|
||||
@@ -167,8 +174,8 @@ func applyMLTranslations(ctx context.Context, tx *gorm.DB, writer TranslationWri
|
||||
return nil
|
||||
}
|
||||
|
||||
// hydrateMLRecord replaces host scalars of declared mltext/mlmarkdown fields
|
||||
// in a Show/save RecordResult.Data map with a locale→text map for every
|
||||
// hydrateMLRecord replaces host scalars of declared mltext/mltextarea/mlmarkdown
|
||||
// fields in a Show/save RecordResult.Data map with a locale→text map for every
|
||||
// enabled code. The default locale is the projected host column; other codes
|
||||
// come from TranslatedExact; a missing non-default code is an empty string,
|
||||
// never D-11 fallback. It is a no-op when writer is nil and is not used from
|
||||
|
||||
Reference in New Issue
Block a user