Collection
The Collection
type generates a field for
Inline-Relational-Record-Editing (IRRE), which
allows nesting of other field types. This field type allows
building structures like image sliders, accordions, tabs and so on.
Collections will automatically create custom tables and use the
identifier
as table name. It is possible to override this with the
setting table
. Collections are always hidden in the List
module. Usually Collections only have one type. To realise multiple types it is
recommended to extract the definition to a separate
Record Type and use
foreign_table instead.
Custom icon
In order to define a custom icon for your Collection field, you may place an
image file inside assets folder called {identifier}.svg. So for example
if your identifier for the Collection is my_
, then your image
should be named my_collection.svg. Alternatively, you can also provide png
or gif files. These should be 64x64px.
Settings
labelField
-
- Type
- string|array
- Required
true
Defines which field should be used as the title of the record. If not defined, the first valid child field will be used as the label. It is possible to define an array of fields, which will be displayed comma-separated in the backend.
# a single field for the label labelField: title # multiple fields will be displayed comma-separated labelField: - title - text
Copied!
fallbackLabelFields
-
- Type
- array
Defines which fields should be used as fallback, if
label
is not filled. The first filled field which is found will be used. Can only be used if there is only oneField label
field defined.Field # fallback fields will be used, if title from labelField is empty labelField: title fallbackLabelFields: - text1 - text2
Copied!
table
-
- Type
- string
Alternative table name for the Collection. Default is
identifier
with prefix if enabled.table: tx_vendor_my_custom_table_name
Copied!
fields
-
- Type
- array
- Required
true
Configures a set of fields as repeatable child objects. All fields defined in field types are possible as children. It is also possible to further nest Collection fields.
Example:
fields: - identifier: text type: Text - identifier: image type: File
Copied!
minitems
-
- Type
- integer
- Default
- "0"
Minimum number of child items. Defaults to 0. JavaScript record validation prevents the record from being saved if the limit is not satisfied.
maxitems
-
- Type
- integer
- Default
- "0"
Maximum number of child items. Defaults to a high value. JavaScript record validation prevents the record from being saved if the limit is not satisfied.
relationship
-
- Type
- string
- Default
- oneToMany
The relationship defines the cardinality between the relations. Possible values are
one
(default),To Many many
andTo One one
. In case of a [x]toOne relation, the processed field will be filled directly with the record instead of a collection of records. In addition,To One maxitems
will be automatically set to1
.
appearance.collapseAll
-
- Type
- bool|null
- Default
- null
- Default (null): Last collapsed/expanded state is remembered
- true: Show all child records collapsed
- false: Show all child records expanded
appearance.levelLinksPosition
-
- Type
- string
- Default
- top
Defines where to show the "New record" link in relation to the child records. Valid keywords are
top
,bottom
andboth
.
foreign_table
-
- Type
- string (table)
It is possible to reference another table instead of creating a new one. This table can be defined by another Content Block, but can also be an existing table defined by the Core or another extension.
Note
When you use
foreign_
it is not possible to definetable fields
anymore. They will not be evaluated.
foreign_field
-
- Type
- string (field)
It is possible to override the field name pointing to the parent record. Per default it is called
foreign_
. This corresponds with the TCA option foreign_field.table_ parent_ uid
shareAcrossTables
-
- Type
- boolean
- Default
- false
Allows to reference a Record Type across multiple tables, if foreign_table is used.
Make sure to add this to every Collection, which shares the table.
This will create a new field called
tablenames
. It corresponds to the TCA option foreign_table_field. The field name can be overridden by definingforeign_
explicitly.table_ field
shareAcrossFields
-
- Type
- boolean
- Default
- false
Allows to reference a Record Type across multiple fields, if foreign_table is used.
Make sure to add this to every Collection, which shares the table.
This will create a new field called
fieldname
. It corresponds to the TCA option foreign_match_fields.
Example
Minimal
name: example/collection
fields:
- identifier: collection
type: Collection
labelField: text
fields:
- identifier: text
type: Text
Advanced / use case
name: example/collection
fields:
- identifier: slides
type: Collection
labelField: title
maxitems: 5
minitems: 1
appearance:
collapseAll: true
levelLinksPosition: both
fields:
- identifier: image
type: File
minitems: 1
maxitems: 1
- identifier: title
type: Text
This custom table my_
needs to be defined as a
Record Type in order to be used as a foreign
table in slides
.
name: example/slide
table: my_slide
labelField: title
fields:
- identifier: title
type: Text
- identifier: image
type: File
name: example/collection
fields:
- identifier: slides
type: Collection
foreign_table: my_slide
shareAcrossTables: true
shareAcrossFields: true