Form and template¶
The FormMapper maps Field definitions into Symfony forms, allowing Field editing.
It can implement two interfaces:
Ibexa\Contracts\ContentForms\FieldType\FieldValueFormMapperInterfaceto provide editing support
Ibexa\AdminUi\FieldType\FieldDefinitionFormMapperInterfaceto provide Field Type definition editing support, when you require non-standard settings
FieldValueFormMapperInterface::mapFieldValueForm method accepts two arguments:
FormInterface— form for the current Field
FieldData— underlying data for current field form
You have to add your form type to the content editing form. The example shows how
ezboolean injects the form:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
Your type has to be called
In the example above,
CheckboxFieldType::class is used, but you can use standard Symfony form type instead.
It's good practice to encapsulate Fields with custom types as it allows easier templating.
Type has to be compatible with your Field Type's
You can use a
DataTransformer to achieve that or just assure correct property and form field names.
Providing definition editing support is almost identical to creating content editing support. The only difference are field names:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
Use names corresponding to the keys used in Field Type's
defaultValue key allows you to specify a field for setting the default value assigned during content editing.
Registering the service¶
The FormMapper must be registered as a service:
1 2 3 4
Tag the mapper according to the support you need to provide:
- Add the
ibexa.admin_ui.field_type.form.mapper.valuetag when providing content editing support (
- Add the
ibexa.admin_ui.field_type.form.mapper.definitiontag when providing Field Type definition editing support (
fieldTypekey has to correspond to the name of your Field Type.
Content view templates¶
To render the Field in content view by using the
ibexa_render_field() Twig helper,
you need to define a template containing a block for the Field.
1 2 3
By convention, your block must be named
Template blocks for built-in Field Types are available in
This template is also exposed as a part of Standard Design, so you can override it with the design engine.
To do so, place the template
themes/standard/content_fields.html.twig in your
ibexa_standard_design.override_kernel_templates is set to true).
The block can receive the following variables:
||The field to display|
||The ContentInfo of the Content item the Field belongs to|
||The VersionInfo of the Content item the Field belongs to|
||array||Settings of the Field (depends on the Field Type)|
||hash||Options passed to
||hash||The attributes to add the generate the HTML markup, passed to ibexa_render_field()
Contains at least a class entry, containing
For easier Field Type template development you can take advantage of all defined blocks by using the
You can for example use
field_attributes blocks provided in
To be able to reuse built-in blocks, your template must inherit from
Registering a template¶
If you don't use the design engine or you want to have separate templates per Field Type and/or SiteAccess, you can register a template with the following configuration:
1 2 3 4 5 6 7 8
Back Office templates¶
Back Office view template¶
For templates for previewing the Field in the Back Office,
using the design engine is recommended with
ibexa_standard_design.override_kernel_templates set to
With the design engine you can apply a template (e.g.
Resources/views/themes/admin/content_fields.html.twig) without any extra configuration.
If you do not use the design engine, apply the following configuration:
1 2 3 4 5
Field edit template¶
To use a template for the Field edit form in the Back Office, you need to specify it in configuration
1 2 3
We encourage using custom form types for encapsulation as this makes templating easier by providing Twig block name. All built-in Field Types are implemented with this approach. In that case overriding form theme can be done with:
1 2 3 4
For more information on creating and overriding form type templates, see Symfony documentation.