Page tree
Skip to end of metadata
Go to start of metadata
Introduction

Since Magnolia 5.2.5 and Magnolia 5.3, we have introduce a new way to handle transformers that will gives you a lot more of freedom for combining, compose fields.

Assume that you have a multipleField_A that contains a compositeField_B .
Until  Magnolia 5.2.4 the multipleField_A (in fact his transformer) had to handle the whole data structure, meaning, the Items/Properties used by himself, but also by the Items/Properties used by the compositeField_B.
Due to this limitation the multipleField_A is only able to support two levels of fields composition and only with one combination (multiple field  that contains a composite field).
It was not possible to have a:

  • A composite containing a multiple field
  • A composite containing composite field
  • A multiple containing a composite containing a multiple
    ... and so on.

In order to solve this, we have introduces two new transformers that are basically delegating the handling of properties/Items to the next level of fields. Doing so, the multiple transformer creates a list of Items. This Item is then used by the inner field to create/retrieve his own properties. Now we can have

  • A multiple containing a composite that contains a multiple, containing a switchable, ....
    in fact any field structure.

 

DelegatingMultiValueFieldTransformer

The DelegatingMultiValueFieldTransformer doesn't create a node for the multivalue parent field. It creates nodes for the child fields and stores their values as properties. This structure is equivalent to the JCR structure of the form Item.

Transformer class: info.magnolia.ui.form.field.transformer.multi.DelegatingMultiValueFieldTransformer

Here is a multivalue field that consists of a text field.

The DelegatingMultiValueFieldTransformer stores the values like this:

Node nameValue

 shoppingList0

 

 element

milk

 shoppingList1

 

 element

cookies

 shoppingList2

 

 element

pizza

based on the following field definition:

Node nameValue

 shoppingList

 

 field

 

 class

info.magnolia.ui.form.field.definition.TextFieldDefinition

 name

element

 class

info.magnolia.ui.form.field.definition.MultiValueFieldDefinition

 label

Shopping list

 transformerClass

info.magnolia.ui.form.field.transformer.multi.DelegatingMultiValueFieldTransformer

In case of I18n set to true, this transformer retrieve the sub items with the selected extension (shoppingList0_de).

Difference with the previous versions of multi-transformers:

Storing strategy (create sub items for every entry of the multi field)

 

DelegatingCompositeFieldTransformer

The DelegatingCompositeFieldTransformer stores each child field value as a single property.

Transformer class: info.magnolia.ui.form.field.transformer.composite.DelegatingCompositeFieldTransformer

Here is a composite event field. It consists of two text fields .

The DelegatingCompositeFieldTransformer stores the values like this:

Node nameValue

 first

 car

 secondtrain

based on the following field definition:

Node nameValue

 wish

 

 fields

 

 first

standard TextFieldDefinition

 second

standard TextFieldDefinition

 class

info.magnolia.ui.form.field.definition.CompositeFieldDefinition

 label

Wish

 transformerClass

info.magnolia.ui.form.field.transformer.composite.DelegatingCompositeFieldTransformer

In case of I18n set to true, this transformer delegates the I18Nization to his inner fields (first_de).

Difference with the previous versions of composite-transformers:

The name used to store the property of the sub fields are taken from the sub fields

Let say that you have one composite field (name:composite) containing a date (name:date)  and a text (name:text) field. These values are stored under:

  • compositedate
  • compositetext

Now they will be stored under:

  • date
  • text
Combine DelegatingMultiValueFieldTransformer and DelegatingCompositeFieldTransformer  together

Let's take an example:

For some reason we have decided to have a multiple field A that contains a composite field B. The composite field contains two elements:

  • A text field BA
  • A multiple field BB that contains a multiple field BBA

Sequence:

When adding the first composite field B

  • the transformer of the multiple field A create a new Item and pass this Item to the composite field B.
  • This Item is then passed to the fields of B in order to initialize their own properties/items.
    • The text field BA uses the item to add his text property
    • The embedded multiple field BB uses this Item to create a sub Item send to his field  BBA

Jcr representation of this entry :

Assume that we add a new composite Element:

I18N

This delegation also includes full i18n support.

The first level is I18Nsed, but not the child levels.

We can now add the previous multiple field A in a composite field X that also contains a text field Y .
In this example the only I18N field is the multiple field.

 

  • No labels