CAFA is storage for layered custom
configurations, more info.
Goerp has an option to change or create json typed values in the CAFA entry. Using xPath, template
creators can define specific location from the json and modify one field. All implementation options
will create field if it is not existing in json. Also, defining new type for the field will update
the type in json as well, so be careful.
The jsonLookup function accepts single json object and path as a parameters. Path supports
standard xpath queries, more info.
Single input (model JsonConfigurationSingleInput) form is always scoped around one
configuration entry, meaning that when submitting the form, only one config entry gets processed and
updated in the database. It is more performant in comparison with Bulk input saving.
This option should be used when page content consists of one or few configuration entries which have
to describe many fields of each entry. Also, this option is simpler to read (and write) from a code
perspective. We need to provide .Key and .Value only once in the form and then
repeat .FieldPath, .FieldValue and .FieldType for every field from json
object (sample have 4 fields from one json object):
<!-- Would be simpler to store reusable parameters into variables -->{{ $key10 := "my-app::Company::::sample::draft-sample-v1" }}
{{ $v10 := index.Data.CaFaApi.ConfigurationMap $key10 }}
<!-- Single input form --><formmethod="post"><!-- Form control parameter allows to link this form to the specific model --><inputtype="hidden"name="postActionEntity"value="JsonConfigurationSingleInput"><!-- fields related to config entry --><inputtype="hidden"name="CaFaApi.JsonConfigurationSingleInput.Key"value="{{ $key10 }}"><inputtype="hidden"name="CaFaApi.JsonConfigurationSingleInput.Value"value="{{ $v10 }}"><!-- multiple fields from config json value --> {{ $path101 := "content.node-obj.child" }}
<inputtype="hidden"name="CaFaApi.JsonConfigurationSingleInput.FieldPath"value={{$path101}}><labelfor="formInputValue101">{{ $path101 }}</label><inputtype="text"id="formInputValue101"name="CaFaApi.JsonConfigurationSingleInput.FieldValue"value="{{ jsonLookup $v10 $path101 }}"><inputtype="hidden"name="CaFaApi.JsonConfigurationSingleInput.FieldType"value="{{ jsonType $v10 $path101 }}"> {{ $path102 := "content.node-bool" }}
<inputtype="hidden"name="CaFaApi.JsonConfigurationSingleInput.FieldPath"value={{$path102}}><labelfor="formInputValue102">{{ $path102 }}</label><inputtype="text"id="formInputValue102"name="CaFaApi.JsonConfigurationSingleInput.FieldValue"value="{{ jsonLookup $v10 $path102 }}"><inputtype="hidden"name="CaFaApi.JsonConfigurationSingleInput.FieldType"value="{{ jsonType $v10 $path102 }}"> {{ $path103 := "content.node-num" }}
<inputtype="hidden"name="CaFaApi.JsonConfigurationSingleInput.FieldPath"value={{$path103}}><labelfor="formInputValue103">{{ $path103 }}</label><inputtype="text"id="formInputValue103"name="CaFaApi.JsonConfigurationSingleInput.FieldValue"value="{{ jsonLookup $v10 $path103 }}"><inputtype="hidden"name="CaFaApi.JsonConfigurationSingleInput.FieldType"value="{{ jsonType $v10 $path103 }}"> {{ $path104 := "status" }}
<inputtype="hidden"name="CaFaApi.JsonConfigurationSingleInput.FieldPath"value={{$path104}}><labelfor="formInputValue104">{{ $path104 }}</label><inputtype="text"id="formInputValue104"name="CaFaApi.JsonConfigurationSingleInput.FieldValue"value="{{ jsonLookup $v10 $path104 }}"><inputtype="hidden"name="CaFaApi.JsonConfigurationSingleInput.FieldType"value="{{ jsonType $v10 $path104 }}"><inputtype="submit"value="Submit draft-sample-v1"></form>
Bulk input sample
Single input (model JsonConfigurationSingleInput) form is scoped around multiple
configuration entries, meaning that when submitting the form, then every entry would be processed
and updated in the database in the loop (uniqueness defined by $key’s). It is less
performant in comparison with Single input saving (later will be processed asynchronously, meaning
without performance loss, but for now prefer using single input option).
This option should be used when page content consists of many entries having few field inputs for
each. Also, this option is harder to read (and write) from a code perspective. We need to
provide .Key, .Value, .FieldPath, .FieldValue and .FieldType
for every field from json objects. We have here 6 entries, please note that final field declaration
assumes that field may not exist and type can be selected.
Sample code uses some fake data. To make it work properly, please populate your test account with
this fake data (or replace all parameters with your data structure). Just insert this data into CAFA
storage using any rest client.