AfterFlexFormDataStructureIdentifierInitializedEvent¶
New in version 12.0
This event was introduced to replace and improve the method
parse
of the hook
$GLOBALS
.
The PSR-14 event
\TYPO3\
can be used to control the FlexForm parsing in an
object-oriented approach.
See also
Example¶
Registration of the events in the extension's Services.
:
services:
# Place here the default dependency injection configuration
MyVendor\MyExtension\Configuration\EventListener\FlexFormParsingModifyEventListener:
tags:
- name: event.listener
identifier: 'my-extension/set-data-structure'
method: 'setDataStructure'
- name: event.listener
identifier: 'my-extension/modify-data-structure'
method: 'modifyDataStructure'
- name: event.listener
identifier: 'my-extension/set-data-structure-identifier'
method: 'setDataStructureIdentifier'
- name: event.listener
identifier: 'my-extension/modify-data-structure-identifier'
method: 'modifyDataStructureIdentifier'
Read how to configure dependency injection in extensions.
The corresponding event listener class:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Configuration\EventListener;
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:my_extension/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']['sheetTitle'] = 'Some dynamic custom sheet title';
$event->setDataStructure($parsedDataStructure);
}
}
public function setDataStructureIdentifier(BeforeFlexFormDataStructureIdentifierInitializedEvent $event): void
{
if ($event->getTableName() === 'tx_myextension_domain_model_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 AfterFlexFormDataStructureIdentifierInitializedEvent ¶
-
- Fully qualified name
-
\TYPO3\
CMS\ Core\ Configuration\ Event\ After Flex Form Data Structure Identifier Initialized Event
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.- Returns
-
array
- getTableName ( ) ¶
-
- Returns
-
string
- getFieldName ( ) ¶
-
- Returns
-
string
- getRow ( ) ¶
-
Returns the whole database row of the current record.
- Returns
-
array
- setIdentifier ( array $identifier) ¶
-
Allows to modify or completely replace the initialized data structure identifier.
- param $identifier
-
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
Flex
component.Form Tools - Returns
-
array