Search code examples
dialogmagnoliatransformer-model

Which transformerClasses to use for complex Magnolia forms


I need to define a dialog, consisting of a several basic fields (text) nested in a switchable field, which itself is nested in a composite field, which itself is nested in a multivalue field.

Multivalue 
  -> Composite
    -> Switchable
       -> textField1
       -> textField2
    -> generic textField (belonging to  composite, but not to switchable)

However i cant manage to find the correct and working combination of transformerClasses, which I need to use. If using the corresponding DelegatingXXTransformer classes on multiValue and composite field, it nearly worked as expected, but those delegating transformers hide the required UI-controls (arrow down/up) buttons (see image). But I need those controls. I need the information which transformerClass to use for any element, to dont lose the ui controls, but still be able to handle nested fields with a higher level than two. Anyway to solve this ?

enter image description here

relevant yaml-config:

form:
  tabs:
   - name: tabMain
     fields:
      - name: mainNav
        class: info.magnolia.ui.form.field.definition.MultiValueFieldDefinition
        transformerClass: info.magnolia.ui.form.field.transformer.multi.DelegatingMultiValueSubnodeTransformer
        field:
          name: composite
          class: info.magnolia.ui.form.field.definition.CompositeFieldDefinition
          transformerClass: info.magnolia.ui.form.field.transformer.composite.DelegatingCompositeFieldTransformer
          layout: vertical
          fields:
            - !include /module-ui/dialogs/common/link.yaml
            - !include /module-ui/common/link-title.yaml
            - !include /module-ui/dialogs/common/link-target.yaml
actions: !include /module-ui/dialogs/actions/default.yaml

link.yaml:

name: link
class: info.magnolia.ui.form.field.definition.SwitchableFieldDefinition
transformerClass: info.magnolia.ui.form.field.transformer.composite.SwitchableTransformer
options:
 - name: internal
   value: internal
   selected: true
 - name: external
   value: external
   fields:
    - name: internal
      class: info.magnolia.ui.form.field.definition.LinkFieldDefinition
      appName: pages
      identifierToPathConverter:
        class:    info.magnolia.ui.form.field.converter.BaseIdentifierToPathConverter
 - name: external
   class: info.magnolia.ui.form.field.definition.TextFieldDefinition
   defaultValue: "http://"

Solution

  • Delegating transformers do not support ordering of the sub fields in multi field. This is due to the fact that they simply delegate persistence down to each individual field and have no control over how those fields will be persisted. Those sub fields then have no knowledge of the surrounding fields so they can't do anything either.

    The only solution is to use other than delegating transformers or if none of the out of the box available transformers suit your needs, write your own.

    Jan