BeforeRecordLanguageOverlayEvent
The PSR-14 event
\TYPO3\
can be used to modify information (such as the
LanguageAspect or the actual incoming
record from the database) before the database is queried.
See also
Example: Change the overlay type to "on" (connected)
In this example, we will change the overlay type to "on" (connected). This may be necessary if your site is configured with free mode, but you have a record type that has languages connected.
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Domain\Language;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Context\LanguageAspect;
use TYPO3\CMS\Core\Domain\Event\BeforeRecordLanguageOverlayEvent;
#[AsEventListener(
identifier: 'my-extension/before-record-language-overlay',
)]
final readonly class MyEventListener
{
public function __invoke(BeforeRecordLanguageOverlayEvent $event): void
{
if ($event->getTable() !== 'tx_myextension_domain_model_record') {
return;
}
$currentLanguageAspect = $event->getLanguageAspect();
$newLanguageAspect = new LanguageAspect(
$currentLanguageAspect->getId(),
$currentLanguageAspect->getContentId(),
LanguageAspect::OVERLAYS_ON,
$currentLanguageAspect->getFallbackChain(),
);
$event->setLanguageAspect($newLanguageAspect);
}
}
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/Services.yaml
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.