File tree Expand file tree Collapse file tree 3 files changed +53
-3
lines changed
Documentation/ApiOverview/Events/Events/Core/Domain
_BeforeRecordLanguageOverlayEvent Expand file tree Collapse file tree 3 files changed +53
-3
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,9 @@ The PSR-14 event :php:`\TYPO3\CMS\Core\Domain\Event\AfterRecordLanguageOverlayEv
1414can be used to modify the actual translated record (if found) to add additional
1515information or perform custom processing of the record.
1616
17+ .. seealso ::
18+ * :ref: `BeforeRecordLanguageOverlayEvent `
19+
1720Example
1821=======
1922
Original file line number Diff line number Diff line change @@ -15,10 +15,25 @@ can be used to modify information (such as the
1515:ref: `LanguageAspect <context_api_aspects_language >` or the actual incoming
1616record from the database) before the database is queried.
1717
18- Example
19- =======
18+ .. seealso ::
19+ * :ref: ` AfterRecordLanguageOverlayEvent `
2020
21- .. include :: /_includes/EventsContributeNote.rst.txt
21+ .. _BeforeRecordLanguageOverlayEvent-example :
22+
23+ Example: Change the overlay type to "on" (connected)
24+ ====================================================
25+
26+ In this example, we will change the overlay type to "on" (connected). This may
27+ be necessary if your site is configured with free mode, but you have a record
28+ type that has languages connected.
29+
30+ .. literalinclude :: _BeforeRecordLanguageOverlayEvent/_MyEventListener.php
31+ :language: php
32+ :caption: EXT:my_extension/Classes/Domain/Language/MyEventListener.php
33+
34+ .. include :: /_includes/EventsAttributeAdded.rst.txt
35+
36+ .. _BeforeRecordLanguageOverlayEvent-api :
2237
2338API
2439===
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace MyVendor \MyExtension \Domain \Language ;
6+
7+ use TYPO3 \CMS \Core \Attribute \AsEventListener ;
8+ use TYPO3 \CMS \Core \Context \LanguageAspect ;
9+ use TYPO3 \CMS \Core \Domain \Event \BeforeRecordLanguageOverlayEvent ;
10+
11+ #[AsEventListener(
12+ identifier: 'my-extension/before-record-language-overlay ' ,
13+ )]
14+ final readonly class MyEventListener
15+ {
16+ public function __invoke (BeforeRecordLanguageOverlayEvent $ event ): void
17+ {
18+ if ($ event ->getTable () !== 'tx_myextension_domain_model_record ' ) {
19+ return ;
20+ }
21+
22+ $ currentLanguageAspect = $ event ->getLanguageAspect ();
23+ $ newLanguageAspect = new LanguageAspect (
24+ $ currentLanguageAspect ->getId (),
25+ $ currentLanguageAspect ->getContentId (),
26+ LanguageAspect::OVERLAYS_ON ,
27+ $ currentLanguageAspect ->getFallbackChain (),
28+ );
29+
30+ $ event ->setLanguageAspect ($ newLanguageAspect );
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments