Review 13.4 Merged

93144[BUGFIX] Properly persist ENV variables in site config (rootPageId)

Garvin Hicking CR +2 V +2 Hard +323 −60 updated 03/10/26, 14:14

Commit message

With this patch, ENV placeholder variables can be used for
site configuration dropdowns like rootPageId, without
failing to display the current config in the GUI or
failing to persist any site configuration where such a config
is utilized.

Details:

The site config (sites/xxx/config.yaml) allows to process YAML
placeholders. This can be properly utilized already for plaintext
input fields like `base` and `websiteTitle`, so that in the
config GUI these will contain the values like

```
  base: 'https://%env(DDEV_HOSTNAME)%/styleguide-demo'
```

Saving this in the GUI will keep the value, as intended.
Saving `%env(...)` placeholders via GUI in any variable that
did not yet contain an ENV variable will fail due to security
reasons.

However, applying the same ENV replacement logic for a select-field
like `rootPageId` fails due to:

1) The backend config GUI will show a root page id select dropdown
   with the entry "MISSING LABEL ("%env...%)", revealing that
   no page id resolving takes place in the GUI (good, in theory).

2) When saving this, the value will be invalidated, the rootPage
   not be resolved, ending in an exception for "Existing config
   for site xxx-[randomhash] not found". This happens because
   TYPO3 treats the config as a "new site", create an empty directory
   and fails to populate the config (rightly so).

3) Re-entering the site config will reveal the stored flash messages:

   ```
      Renamed identifier
      Given site identifier "main" already exists. It has been renamed
      to "main-6985fec488155032110726". Maybe you want to edit the site
      again and give it a better name.

      Introducing placeholder %env(BASE_URI)% for base is not allowed
   ```

The reason for why the rootPageId resolve fails is, the
`AbstractItemProvider` would remove the given value from
passed-through `databaseRow`, as the value is (by foreign_table clause)
not a  valid root-page-id.

On save of site-configuration the ENV-variable based root-page-id
would get lost on int conversion.

To fix this, this patch:

- Makes use of a specific EnvPlaceholderProcessor which does isolated
  replacements. The code is based on what the YamlFileLoader() already
  did, and makes it usable outside the whole YAML loading process.
  That processor is able to parse a single value with possibly multiple
  ENV placeholders.

- This new placeholder processing is then used to check whether the
  current root-page-id actually is an ENV placeholder.
  If yes => temporarily accept the value as an allowed value.

- On save, the same placeholder processing is used to process the
  page-id, so TYPO3 duplication checks and root-page-id checks can take
  place. Finally, the unprocessed value (placeholder) is used again for
  persistence into config.yaml.

This whole logic also applies to any other TcaSelect-type field
of the site-config which contains an ENV placeholder.

Review

  • Code review CR +2 Done
    • Garvin Hicking +2
  • Verified V +2 Done
    • Garvin Hicking +2
    • core-ci +1 CI

Issues 1

Files 10

Review log 69

  1. Garvin Hicking commented on patch set 1 03/10/26, 13:11

    Cherry Picked from branch main. The following files contain Git conflicts: * typo3/sysext/backend/Classes/Controller/SiteConfigurationController.php * typo3/sysext/backend/Classes/Form/FormDataProvider/AbstractItemProvider.php * typo3/sysext/backend/Classes/Form/FormDataProvider/TcaSiteLanguage.php * typo3/sysext/backend/Tests/Functional/Form/FormDataProvider/TcaSelectItemsTest.php
  2. core-ci voted on patch set 1 V -1 03/10/26, 13:17 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97696

  3. Garvin Hicking commented on patch set 2 V -1 03/10/26, 13:18

    Published edit on patch set 1.
  4. core-ci voted on patch set 2 V +1 03/10/26, 13:29 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97699

  5. Garvin Hicking commented on patch set 3 V +1 03/10/26, 14:02

    Published edit on patch set 2.
  6. Garvin Hicking marked it ready for review 03/10/26, 14:06

  7. core-ci voted on patch set 3 V +1 03/10/26, 14:09 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97702

  8. Garvin Hicking voted on patch set 3 CR +2 V +2 03/10/26, 14:14

  9. Garvin Hicking merged patch set 4 03/10/26, 14:14