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
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Configuration\EventListener;
use TYPO3\CMS\Core\Attribute\AsEventListener;
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;
#[AsEventListener(
identifier: 'my-extension/set-data-structure',
method: 'setDataStructure',
)]
#[AsEventListener(
identifier: 'my-extension/modify-data-structure',
method: 'modifyDataStructure',
)]
#[AsEventListener(
identifier: 'my-extension/set-data-structure-identifier',
method: 'setDataStructureIdentifier',
)]
#[AsEventListener(
identifier: 'my-extension/modify-data-structure-identifier',
method: 'modifyDataStructureIdentifier',
)]
final readonly 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);
}
}
New in version 13.0
The PHP attribute \TYPO3\
has been
introduced to tag a PHP class as an event listener. Alternatively, or if you
need to be compatible with older TYPO3 versions, you can also register an
event listener via the Configuration/
file. Switch to
an older version of this page for an example or have a look at the section
Implementing an event listener in your extension.
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