Issue Bug Needs Feedback

#103364Site config settings can't be used to override constants anymore

Philipp Kitzberger 03/11/24, 17:23 updated 11/19/26, 13:49

Description

Before TYPO3 12 it was possible to have recursive constants, which made it possible to set TS constants to values defined in the site config settings.

I get that the (undocumented) 10-step-recursion-resolving had to go. So no argument with that. But I’d like to find a solution for the evident drawback I’m facing now.

As soon as I include an extensions TypoScript (that is constants+setup, with constants usually set to empty values), it’s not possible to override those constants with “site constants” anymore.

A workaround could be to override those parts of the setup (where the constants are being read) and change the name of the constants! Since variables are often being used in multiple parts of the setup stack that cannot be the solution.

Take this (randomly chosen) snippet from EXT:powermail’s TypoScript setup:

plugin.tx_powermail.settings.setup.main.pid = {$plugin.tx_powermail.settings.main.pid}

In order to override that setting I would have to change the TypoScript setup to this e.g.

plugin.tx_powermail.settings.setup.main.pid = {$plugin.tx_powermail.settings.main.pid_override_from_site}

And add this new constant to the site config:

settings:
  plugin:
    tx_powermail:
      setup:
        main:
          pid_override_from_site_config: 123

Here’s a screenshot of how the constant stack is being put together:

Bildschirmfoto%20vom%202024-03-11%2018-36-54.png

With TYPO3 11 one simply had to set the extension’s constant to the custom constant (and it’s been resolves correctly) while the extension’s setup could remain untouched.

plugin.tx_powermail.settings.main.pid = {$plugin.tx_powermail.settings.main.pid_override_from_site}

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

Fix this issue

Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". How to create a patch

Commit message
[BUGFIX] Site config settings can't be used to override constants anymore Resolves: #103364 Releases: main

Files 1

History 14

  1. Philipp Kitzberger changed attached Bildschirmfoto vom 2024-03-11 18-36-54.png description <span data-processor="relativetime" data-value="2024-03-11T17:41:37+00:00" > 03/11/24, 17:41 </span>

  2. Philipp Kitzberger changed Bildschirmfoto vom 2024-03-11 18-36-54.png <span data-processor="relativetime" data-value="2024-03-12T08:17:38+00:00" > 03/12/24, 08:17 </span>

  3. Philipp Kitzberger changed attached Bildschirmfoto vom 2024-03-11 18-36-54.png <span data-processor="relativetime" data-value="2024-03-12T08:19:09+00:00" > 03/12/24, 08:19 </span>

  4. Stefan Bürk commented <span data-processor="relativetime" data-value="2024-03-14T14:23:27+00:00" > 03/14/24, 14:23 </span>

    You already described what to do – set your custom constant setting in the TypoScript SETUP to your constant (from SiteConfig).

    Not tested, but maybe it works also if you use the “powermail” default constant name in the SiteConfig ?

  5. Philipp Kitzberger commented <span data-processor="relativetime" data-value="2024-03-14T16:14:54+00:00" > 03/14/24, 16:14 </span>

    Stefan Bürk wrote in #note-7:
    > You already described what to do – set your custom constant setting in the TypoScript SETUP to your constant (from SiteConfig).

    That’s not a good solution, it’s merely a workaround. The whole purpose of constants is that they can be adjusted once and affect multiple (unknown) parts of the setup where they’re being used.

    > Not tested, but maybe it works also if you use the “powermail” default constant name in the SiteConfig ?

    As I’ve mentioned above, that isn’t working as soon as a extensions static TS has being included. Because this then overwrites the constants with “” ;-(

  6. Christian Kuhn commented <span data-processor="relativetime" data-value="2024-03-18T13:23:48+00:00" > 03/18/24, 13:23 </span>

    I’ve had a look at this issue together with Benjamin Franzke, who is currently working on a revamped ‘settings’ API:

    This is essentially a load-order issue that stems from the situation that site settings ‘constants’ are loaded first, and extension includes afterwards. The v13 works in this area will lead to the situation that sites define such extensions TS like powermail as ‘dependencies’, will load them first, and afterwards ‘overload’ with own (site specific) settings. (This will also allow instances without sys_template records).

    However, there may be an additional solution (but I did not had a look if that could be implemented easily): We could implement a TS ‘function’ that does this: “some.constant := ifNotDefined(42)” Thus, a TS function that says “set this constant to a default value, if not yet set”. A “late default”, so to speak. Extensions like powermail would then have to be changed to actively use this, though. But it would resolve your scenario.

  7. Philipp Kitzberger commented <span data-processor="relativetime" data-value="2024-03-19T13:58:55+00:00" > 03/19/24, 13:58 </span>

    Christian Kuhn wrote in #note-9:
    > However, there may be an additional solution (but I did not had a look if that could be implemented easily): We could implement a TS ‘function’ that does this: “some.constant := ifNotDefined(42)” Thus, a TS function that says “set this constant to a default value, if not yet set”. A “late default”, so to speak. Extensions like powermail would then have to be changed to actively use this, though. But it would resolve your scenario.

    I’d prefer an alternative approach to this, mainly because it’s unlikely that all extension authors will change their TS to use that new function.

    So what about the other way round?

    some.constant := overrideWithSiteSetting(some.constant)

    That way an integrator could do the following:

    • Include an extensions TypoScript (constants + setup)
    • After that: modify that extensions constants
      • either by setting it to a hard coded value (like always)
      • or by setting it to the new overrideWithSiteSetting() function to basically explicitly allow TS constants being set in the site settings

    For example:

    @import 'EXT:powermail/Configuration/TypoScript/Main/constants.typoscript'
    plugin.tx_powermail.settings.main.pid := overrideWithSiteSetting(${plugin.tx_powermail.settings.main.pid})

    On some deeper level of the page tree, it’d be still possible to override that constant of course:

    [page|uid = 3]
    plugin.tx_powermail.settings.main.pid = 123
    [global]

    This would basically be a comeback of the former recursive voodoo but explicitly used and much cleaner.

  8. Benni Mack commented and changed status New Closed <span data-processor="relativetime" data-value="2026-11-19T13:49:02+00:00" > 11/19/26, 13:49 </span>

    Short status update for current versions.

    With TYPO3 v13 and newer this is solved by site sets. When a site uses sets, the TypoScript of those sets loads first and the site settings are applied afterwards. So the extension’s constants can be overridden from the site settings under their own name, without a second constant:

    # config/sites/<site>/config.yaml
    dependencies:
      - vendor/powermail   # or a local set that includes the extension's TypoScript
    
    # config/sites/<site>/settings.yaml
    plugin:
      tx_powermail:
        settings:
          main:
            pid: 123

    The order is different for setups based on sys_template records. Site settings are loaded first there, as defaults that the record’s includes and constants can override. That order is intended and we won’t change it, because existing installations rely on it.

    For such setups you can copy the value in the constants field of the sys_template record. The copy operator works in constants, and that field is evaluated after the static includes:

    plugin.tx_powermail.settings.main.pid < mysite.pid

    Unlike {$...}, this doesn’t need the recursive constant resolving that was removed in v12 (see #97816).

    Because site sets now cover this, I’d rather not add a new TypoScript function like ifNotDefined() or overrideWithSiteSetting(). If neither way works for your setup, please describe it here. Otherwise I’d close the issue.