Sometimes it's required to set specific data for a given form field.
To do that, we usually fill up the data
options field.
In case this data should be fluid, you need to hook into some form events which requires developers to do that.
To make things easier, we've introduced the Data Injection Section.
There is also a preconfigured expression
injector.
This feature is available for:
- Hidden Type
- Integer Type
- Text Type
- Textarea Type
Use this injector for the most common scenario: Link a request parameter to a given form.
Within the expression injecor, you're allowed to fetch data from symfonys request
object.
Example: request.query.get('myEventId')
or request.attributes.get('siteId')
services:
App\Form\DataInjector\MyDataInjector:
tags:
- { name: form_builder.data_injector, identifier: my_data_injector }
<?php
namespace App\FormBuilder\Form\DataInjector;
class MyDataInjector implements DataInjectorInterface
{
public function getName(): string
{
return 'My Data Injector';
}
public function getDescription(): ?string
{
return 'My Description';
}
public function parseData(array $config): mixed
{
if (!array_key_exists('my_additional_config_node', $config)) {
return null;
}
$config = $config['my_additional_config_node'];
// do your logic
$newData = null;
return $newData;
}
}
pimcore.registerNS('Formbuilder.extjs.form.dataInjection.my_data_injector');
Formbuilder.extjs.form.dataInjection.my_data_injector = Class.create({
getForm: function (data) {
return [{
xtype: 'textfield',
fieldLabel: 'Required Additional Config Node',
name: 'my_additional_config_node',
anchor: '100%',
allowBlank: false,
value: data !== null ? data.my_additional_config_node : null
}];
}
});