AfterFlexFormDataStructureIdentifierInitializedEvent¶
New in version 12.0: This event was introduced to replace and improve the method
parseDataStructureByIdentifierPostProcess()
of the hook
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['workspaces']['modifyDifferenceArray']
.
The PSR-14 event
\TYPO3\CMS\Core\Configuration\Event\AfterFlexFormDataStructureIdentifierInitializedEvent
can be used to control the FlexForm parsing in an
object-oriented approach.
See also
Example¶
This example is available in our examples extension.
Registration of the events in the extension's Services.yaml
:
services:
# Place here the default dependency injection configuration
T3docs\Examples\EventListener\Core\Configuration\FlexFormParsingModifyEventListener:
tags:
- name: event.listener
identifier: 'form-framework/set-data-structure'
method: 'setDataStructure'
- name: event.listener
identifier: 'form-framework/modify-data-structure'
method: 'modifyDataStructure'
- name: event.listener
identifier: 'form-framework/set-data-structure-identifier'
method: 'setDataStructureIdentifier'
- name: event.listener
identifier: 'form-framework/modify-data-structure-identifier'
method: 'modifyDataStructureIdentifier'
Read how to configure dependency injection in extensions.
The corresponding event listener class:
use TYPO3\CMS\Core\Configuration\Event\AfterFlexFormDataStructureIdentifierInitializedEvent;
use TYPO3\CMS\Core\Configuration\Event\AfterFlexFormDataStructureParsedEvent;
use TYPO3\CMS\Core\Configuration\Event\BeforeFlexFormDataStructureIdentifierInitializedEvent;
use TYPO3\CMS\Core\Configuration\Event\BeforeFlexFormDataStructureParsedEvent;
final class FlexFormParsingModifyEventListener
{
public function setDataStructure(BeforeFlexFormDataStructureParsedEvent $event): void
{
$identifier = $event->getIdentifier();
if (($identifier['type'] ?? '') === 'my_custom_type') {
$event->setDataStructure('FILE:EXT:myext/Configuration/FlexForms/MyFlexform.xml');
}
}
public function modifyDataStructure(AfterFlexFormDataStructureParsedEvent $event): void
{
$identifier = $event->getIdentifier();
if (($identifier['type'] ?? '') === 'my_custom_type') {
$parsedDataStructure = $event->getDataStructure();
$parsedDataStructure['sheets']['sDEF']['ROOT']['TCEforms']['sheetTitle'] = 'Some dynamic custom sheet title';
$event->setDataStructure($parsedDataStructure);
}
}
public function setDataStructureIdentifier(BeforeFlexFormDataStructureIdentifierInitializedEvent $event): void
{
if ($event->getTableName() === 'tx_myext_sometable') {
$event->setIdentifier([
'type' => 'my_custom_type',
]);
}
}
public function modifyDataStructureIdentifier(AfterFlexFormDataStructureIdentifierInitializedEvent $event): void
{
$identifier = $event->getIdentifier();
if (($identifier['type'] ?? '') === 'some_other_type') {
$identifier['type'] = 'my_custom_type';
}
$event->setIdentifier($identifier);
}
}
API¶
- class TYPO3\CMS\Core\Configuration\Event\AfterFlexFormDataStructureIdentifierInitializedEvent¶
Listeners to this event are able to modify or enhance the data structure identifier, which is used for a given TCA flex field.
This event can be used to add additional data to an identifier. Be careful here, especially if stuff from the source record like uid or pid is added! This may easily lead to issues with data handler details like copy or move records, localization and version overlays. Test this very well! Multiple listeners may add information to the same identifier here - take care to namespace array keys. Information added here can be later used in the data structure related PSR-14 Events (BeforeFlexFormDataStructureParsedEvent and AfterFlexFormDataStructureParsedEvent) again.
See the note on FlexFormTools regarding the schema of $dataStructure.
- getFieldTca()¶
Returns the full TCA of the currently handled field, having
type=flex
set.- Return type
array
- getTableName()¶
- Return type
string
- getFieldName()¶
- Return type
string
- getRow()¶
Returns the whole database row of the current record.
- Return type
array
- setIdentifier(array $identifier)¶
Allows to modify or completely replace the initialized data structure identifier.
- Parameters
$identifier (
array
) -- the identifier
- getIdentifier()¶
Returns the initialized data structure identifier, which has either been defined by an event listener or set to the default by the
FlexFormTools
component.- Return type
array