Issue Bug Resolved

#106158Missing $LANG variable in Collections using tt_content

Danny Luda 02/12/25, 08:59 updated 11/11/26, 16:15

Description

Describe the bug
If a Content Blocks Collection is using tt_content as a foreign_field and for example a typo3 form is added in this. The $LANG variable is not available in this scope and we get an Exception:
PHP Warning: Undefined global variable $LANG in /html/typo3-composer/vendor/typo3/cms-form/Classes/Domain/Configuration/FlexformConfiguration/Processors/FinisherOptionGenerator.php line 96

To Reproduce
Steps to reproduce the behavior:

Create an Element that uses a Collection with foreign_table: tt_content
Insert a Typo3 Form element into it
Open frontend and get the error
Expected behavior
The Form element gets the $LANG variable in this scope.

TYPO3 Version
13.4.5

Content Blocks Version:
1.1.6

Related issue in Content Blocks: https://github.com/FriendsOfTYPO3/content-blocks/issues/343

YAML configuration:

name: pxproject/specialbox
group: pxproject_content_elements
prefixFields: false
basics:
    - TYPO3/Appearance
fields:
  - identifier: image
    type: File
    maxitems: 1
    minitems: 1
    allowed: common-image-types
  - identifier: content
    type: Collection
    minitems: 1
    required: 1
    foreign_table: tt_content

Reviews 2

Files 2

History 1624

  1. André Buchmann commented <span data-processor="relativetime" data-value="2025-03-21T12:38:31+00:00" > 03/21/25, 12:38 </span>

    Heyho I get the same error message in the Surfcamp 2024 project. This project doesn’t use content blocks.
    https://github.com/TYPO3incubator/surfcamp-team-success

    Happens on the most simple page “Whitepaper” in the project with a real simple form. The form has only the “Confirmation Message” finisher. No Finisher Overrides in the CE.

    The error only occures if there is no backend session.

    Maybe it’s related to PageView and the RenderBlockViewHelper.php 🤔 Investigation started…

  2. André Buchmann commented <span data-processor="relativetime" data-value="2025-03-21T20:33:47+00:00" > 03/21/25, 20:33 </span>

    The issue in the surfcamp project was related to an old implementation of the RenderBlockViewHelper and has been fixed in the project itself.

    https://github.com/TYPO3incubator/surfcamp-team-success/commit/68661f89a8abd1fef71e8238751a9aee4fab2965

  3. Georg Ringer commented and changed status New Needs Feedback <span data-processor="relativetime" data-value="2025-03-31T14:05:32+00:00" > 03/31/25, 14:05 </span>

    I need a way to reproduce that, ideally on main, ideally without contentblocks. cant reproduce with contentblocks on main

  4. Sascha Egerer commented <span data-processor="relativetime" data-value="2025-07-30T16:17:22+00:00" > 07/30/25, 16:17 </span>

    I’ve got the same issue now but it happens in TYPO3\CMS\Form\Domain\Configuration\FlexformConfiguration\Processors\FinisherOptionGenerator in TYPO3 13.4.15

    1. Ensure your’re not logged in as backend user
    2. run vendor/bin/typo3 cache:flush
    3. Call the page with the form plugin
    4. Exception occurs

    #1 ErrorReporting\Warning
    Warning: Undefined global variable $LANG
    
    in /var/www/html/vendor/typo3/cms-form/Classes/Domain/Configuration/FlexformConfiguration/Processors/FinisherOptionGenerator.php line 96

    5. Login into the backend
    6. Load the page with the form again
    7. Form is rendered successful
    -8. Logout from backend-
    -9. Load the page with the form again-
    -10. Form is rendered successful-
    -11. run vendor/bin/typo3 cache:flush-
    -12. Exception occurs-

    So it looks like there is something compiled in the cache.-
    -I’ll try to investigate further.

    Nevermind – it was the frontend cache… So i can still reproduce the issue once not logged in in the backend

    —-

    So the issue comes from \TYPO3\CMS\Core\Domain\Record->toArray() -> $property->instantiate() …

  5. Garvin Hicking commented <span data-processor="relativetime" data-value="2025-07-30T17:19:51+00:00" > 07/30/25, 17:19 </span>

    Hm, seems as if https://github.com/TYPO3/typo3/commit/f0d038e49f7f86c5c6ccf9d56949a12d085a6c71 implemented the LanguageService under the assumption that it is only called in the Backend context. But the bug report show that this is also called in frontend context, maybe with FlexForm refactorings or so?

  6. Sascha Egerer commented <span data-processor="relativetime" data-value="2025-07-30T19:54:14+00:00" > 07/30/25, 19:54 </span>

    Garvin Hicking wrote in #note-9:
    > Hm, seems as if https://github.com/TYPO3/typo3/commit/f0d038e49f7f86c5c6ccf9d56949a12d085a6c71 implemented the LanguageService under the assumption that it is only called in the Backend context. But the bug report show that this is also called in frontend context, maybe with FlexForm refactorings or so?

    I believe the root cause is more closely related to https://github.com/TYPO3/typo3/blob/32975a3a449d0efc64b2a89007cc4f815121e9bf/typo3/sysext/core/Classes/Domain/Record.php#L70. This line evaluates TCA fields and also handles Flexform stuff, which ultimately triggers the AfterFlexFormDataStructureParsedEvent, which is listened to by the FinisherOptionGenerator class. Therefore, I’m not sure.

    In my opinion, if the Record class also needs to parse Flexform configuration, it’s appropriate to call these event handlers in the frontend as well. Consequently, these event handlers must be “compatible” and not rely on $GLOBALS[‘lang’].

    Opinions?

  7. Garvin Hicking commented <span data-processor="relativetime" data-value="2025-08-05T12:06:59+00:00" > 08/05/25, 12:06 </span>

    It took me some time to read and re-read this as these are not my “best domains”.

    I would agree. I think the listeners would need to not rely on LANG and probably conditionally switch to the frontend-compatible translate approach, when unavailable. I’m unsure yet if this flexform parsing could also be triggered in CLI context, then we need “yet another” way of language deduction (or do some “english” instantiation fallback, but that would add a lot of code weight to the listener .)

  8. Marcus Balasch commented <span data-processor="relativetime" data-value="2025-10-10T09:39:58+00:00" > 10/10/25, 09:39 </span>

    I don’t know enough about the context of the architecture at this point, but I’ve found a workaround for myself:

        protected function getLanguageService(): LanguageService
        {
            if (isset($GLOBALS['LANG'])) {
                return $GLOBALS['LANG'];
            } elseif (isset($GLOBALS['TYPO3_REQUEST']) && $GLOBALS['TYPO3_REQUEST'] instanceof \TYPO3\CMS\Core\Http\ServerRequest) {
                $request = $GLOBALS['TYPO3_REQUEST'];
                $language = $request->getAttribute('language') ?? $request->getAttribute('site')->getDefaultLanguage();
                return GeneralUtility::makeInstance(LanguageServiceFactory::class)->createFromSiteLanguage($language);
            }
        }

    But it’s probably like a sledgehammer to crack a nut.

  9. Gerrit Code Review pushed patch set 1 for main to change 95826 status Needs Feedback Under Review <span data-processor="relativetime" data-value="2026-09-14T21:50:41+00:00" > 09/14/26, 21:50 </span>

  10. Georg Ringer commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2026-11-10T14:45:11+00:00" > 11/10/26, 14:45 </span>

    Applied in changeset commit:6947f01820a7c89404b1de0a66242e2cce7ddb28.

  11. Gerrit Code Review pushed patch set 3 for 14.3 to change 97519 status Resolved Under Review <span data-processor="relativetime" data-value="2026-11-11T13:50:11+00:00" > 11/11/26, 13:50 </span>

  12. Georg Ringer commented and changed status Under Review Resolved <span data-processor="relativetime" data-value="2026-11-11T16:15:17+00:00" > 11/11/26, 16:15 </span>

    Applied in changeset commit:e2efe4b24dc4cde84cd0d5b3af20d8c2558bb0bf.