Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info
titleBest practice
Excerpt

It can be difficult to configure the correct transformers for advanced fields and especially for fields with complex nesting.

When nesting switchable fields, use delegating field transformers such as the DelegatingCompositeFieldTransformer since normal non-delegating transformers can only handle two nesting levels.

Switchable field and complex nesting

The example configuration below shows the use of the delegating field transformers for a complex nesting scenario where, at the top level, the user has a two-option switch:

Image Added

The Composite option opens into a composite field with two text fields:

Image Added

The Multi option opens into a multi field that allows the user to add individual text fields (three are shown):

Image Added

The field's YAML configuration:

Code Block
languageyml
switchComposite: 
  class: info.magnolia.ui.form.field.definition.SwitchableFieldDefinition
  label: Option Switch
  selectionType: radio
  transformerClass: info.magnolia.ui.form.field.transformer.composite.DelegatingCompositeFieldTransformer
  type: String
  options:
    switchInnerComposite:
      label: Composite
      value: switchInnerComposite
    switchInnerMulti:
      label: Multi
      value: switchInnerMulti
  fields:
    switchInnerComposite:
      class: info.magnolia.ui.form.field.definition.CompositeFieldDefinition
      label: Composite Field
      transformerClass: info.magnolia.ui.form.field.transformer.composite.DelegatingCompositeFieldTransformer
      fields:
        text1:
          class: info.magnolia.ui.form.field.definition.TextFieldDefinition
          label: Text Field 1
          type: String
        text2:
          class: info.magnolia.ui.form.field.definition.TextFieldDefinition
          label: Text Field 2
          type: String
    switchInnerMulti:
      class: info.magnolia.ui.form.field.definition.MultiValueFieldDefinition
      label: Multi Field
      required: false
      transformerClass: info.magnolia.ui.form.field.transformer.multi.DelegatingMultiValueFieldTransformer
      field:
        class: info.magnolia.ui.form.field.definition.MultiValueFieldDefinition
        name: newSubMultiple
        required: false
        transformerClass: info.magnolia.ui.form.field.transformer.multi.DelegatingMultiValueFieldTransformer
        field:
          class: info.magnolia.ui.form.field.definition.TextFieldDefinition
          name: nameProperty
          type: String
transformer classes, DelegatingCompositeFieldTransformer or DelegatingMultiValueFieldTransformer, rather than the other available transformer classes.