Issue Bug Closed

#98588Condition for colpos not working in PageTSConfig

Bernhard Eckl 10/12/22, 12:50 updated 08/27/26, 20:54

Description

The following condition does not work (tested in TYPO3 10 and 11):

[request.getQueryParams()[‘defVals’][‘tt_content’][‘colPos’] == 3]
TCEFORM.tt_content.header_layout.removeItems = 1,2,6,8,9,10
[end]

But it should according to:
https://forge.typo3.org/issues/91646
https://wiki.sebkln.de/doku.php?id=typo3:about:conditions

Is there another syntax to query the colpos?

Reviews 0

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

History 11

  1. Christoph Lehmann commented <span data-processor="relativetime" data-value="2022-11-11T20:22:12+00:00" > 11/11/22, 20:22 </span>

    Does traverse() solve it for you?

    This works

    [traverse(request.getQueryParams(), 'defVals/tt_content/sys_language_uid') == 0]
    TCEFORM.tt_content.header.disabled=1
    [end]

    When using traverse() you also don’t get undefined key warnings in newer PHP versions.

    See https://docs.typo3.org/m/typo3/reference-typoscript/main/en-us/Conditions/Index.html#traverse

  2. Georg Ringer commented and changed status New Accepted <span data-processor="relativetime" data-value="2024-06-07T12:35:04+00:00" > 06/07/24, 12:35 </span>

    still valid in v13

  3. Clemens Riccabona commented <span data-processor="relativetime" data-value="2025-07-23T11:35:50+00:00" > 07/23/25, 11:35 </span>

    does not work in v12 either.

    this breaks backend completely:

    [request.getQueryParams()['defVals']['tt_content']['colPos'] == 3]

    these two just do nothing / are ignored:

    [request && traverse(request.getQueryParams(),'defVals/tt_content/colPos') == 3]
    
    [traverse(request.getQueryParams(),'defVals/tt_content/colPos') == 3]
  4. Ayke Halder commented <span data-processor="relativetime" data-value="2025-08-22T14:13:48+00:00" > 08/22/25, 14:13 </span>

    On my system with TYPO3 v12 this condition in Page.tsconfig works:

    [traverse(request.getQueryParams(), 'defVals/tt_content/colPos') == 1 or traverse(request.getQueryParams(), 'colPos') == 1 or ttContentEdit('colPos') == 1]
      TCEFORM.tt_content {
        layout {
          keepItems = 0
          addItems {
            601 = Teaser
          }
        }
    
        header_layout {
          removeItems = 0,1,3,4,5
        }
      }
    
      TCAdefaults.tt_content.layout = 601
    [global]

    With custom condition function provider ttContentEdit

    example_extension/Classes/TypoScript/TtContentConditionFunctionsProvider.php:

    <?php
    
    namespace Vendor\ExampleExtension\TypoScript;
    
    /**
     * TS conditions for tt_content editing dialogue
     *
     * @author Ayke Halder <mail@ayke-halder.de>
     * @package ExampleExtension
     */
    
    use Symfony\Component\ExpressionLanguage\ExpressionFunction;
    use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
    use TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction;
    use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
    use TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction;
    use TYPO3\CMS\Core\Utility\GeneralUtility;
    use TYPO3\CMS\Core\Database\ConnectionPool;
    
    class TtContentConditionFunctionsProvider implements ExpressionFunctionProviderInterface
    {
    
        public function __construct(private readonly ConnectionPool $connectionPool)
        {
        }
    
        /**
         * @return ExpressionFunction[]
         */
        public function getFunctions(): array
        {
            return [
                $this->getTtContentEditFunction(),
            ];
        }
    
        protected function getTtContentEditFunction(): ExpressionFunction
        {
            return new ExpressionFunction('ttContentEdit', function () {
                // Not implemented, we only use the evaluator
            }, function ($existingVariables, $field) {
                if (!isset($_GET['edit']['tt_content'])) {
                    return false;
                }
    
                $table = 'tt_content';
                list($uid) = GeneralUtility::intExplode(',', (string)key($_GET['edit']['tt_content']), true, 1);
    
                $queryBuilder = $this->connectionPool->getQueryBuilderForTable($table);
    
                $queryBuilder->getRestrictions()
                    ->removeByType(StartTimeRestriction::class)
                    ->removeByType(EndTimeRestriction::class)
                    ->removeByType(HiddenRestriction::class);
    
                $result = $queryBuilder
                    ->select($field)
                    ->from($table)
                    ->where(
                        $queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid))
                    )
                    ->setMaxResults(1)
                    ->executeQuery()
                    ->fetchOne();
    
                if ($result !== false) {
                    return $result;
                }
    
                return false;
            });
        }
    }

    example_extension/Classes/ExpressionLanguage/TypoScriptConditionProvider.php:

    <?php
    
    namespace Vendor\ExampleExtension\ExpressionLanguage;
    
    /**
     * TS condition provider
     *
     * @author Ayke Halder <mail@ayke-halder.de>
     * @package ExampleExtension
     */
    
    use Vendor\ExampleExtension\TypoScript\TtContentConditionFunctionsProvider;
    use TYPO3\CMS\Core\ExpressionLanguage\AbstractProvider;
    
    class TypoScriptConditionProvider extends AbstractProvider
    {
        public function __construct()
        {
            $this->expressionLanguageProviders = [
                TtContentConditionFunctionsProvider::class,
            ];
        }
    }

    example_extension/Configuration/Services.yaml:

    services:
      _defaults:
        autowire: true
        autoconfigure: true
        public: false
    
      Vendor\ExampleExtension\:
        resource: '../Classes/*'
        exclude: '../Classes/Domain/Model/*'
    
      Vendor\ExampleExtension\TypoScript\TtContentConditionFunctionsProvider:
        public: true
  5. Georg Ringer commented and changed status Accepted Closed <span data-processor="relativetime" data-value="2026-08-25T17:13:45+00:00" > 08/25/26, 17:13 </span>

    This can not be fixed as a bug: request-based conditions in page TSconfig and
    user TSconfig were removed on purpose in v13.

    They were deprecated in v12.3 with #100047 and removed with #101053 as part of
    #100963. The reasoning from
    Deprecation-100047-PageTsConfigAndUserTsConfigMustNotRelyOnRequest.rst:

    Page TSconfig and user TSconfig should not rely on request related data […]
    the main reason is that the Backend DataHandler makes heavy use of page
    TSconfig, but the DataHandler itself is not request-aware. The DataHandler
    […] can be used and must work in a CLI context, so any page TSconfig that
    depends on a given request is flawed by design since it will never act as
    expected in a CLI context.

    What happens today: PageTsConfigFactory::create() builds the condition
    variables from fullRootLine, site, page and pageId only – there is no request
    among them. IncludeTreeConditionMatcherVisitor then fills the gap with

    } elseif (!isset($variables['request'])) {
        $variables['request'] = new RequestWrapper(null);
    }

    and RequestWrapper wraps that null into an empty ServerRequest. So
    request.getQueryParams() returns an empty array in page TSconfig, always. Of
    all callers of initializeExpressionMatcherWithVariables(), only
    FrontendTypoScriptFactory passes a real request.

    That explains every observation in this issue:

    • [request.getQueryParams()[‘defVals’][‘tt_content’][‘colPos’] == 3] accesses
      an array key on an empty array. That raises “Undefined array key” warnings,
      which become an exception on installations that have E_WARNING in
      SYS/exceptionalErrors – matching the “breaks backend completely” report.
    • traverse(request.getQueryParams(), ‘defVals/tt_content/colPos’) traverses an
      empty array, returns an empty value and therefore never matches. Hence “just
      do nothing / are ignored”.
    • The working example with ttContentEdit() works because that custom function
      reads $_GET[‘edit’][‘tt_content’] directly and bypasses the expression
      language variable. The two “request…” branches of that or-condition are
      dead code in that snippet.

    Worth noting for the record: this issue quotes #91646, where the syntax was
    recommended in 2020. That advice was correct for v10 and v11. Nobody revisited
    #91646 or this issue when the feature was deprecated and removed, which is why
    the syntax is still passed around.

    Migration for the use case in this issue e.g. a dedicated FormDataProvider.

  6. Ayke Halder commented <span data-processor="relativetime" data-value="2026-08-26T15:47:16+00:00" > 08/26/26, 15:47 </span>

    In the end all the conditons fullRootLine, page and pageId might actually be based on the request:

    • NewRecordController::mainAction(ServerRequestInterface $request) with $pageUid = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0)
    • —> @BackendUtility::getPagesTSconfig($pageUid)@:
    • —> PageTsConfigFactory::create(array $fullRootLine, …)

    Or

    • DatabaseRecordLinkBuilder::getPageTsConfig(ServerRequestInterface $request) with
    • $pageInformation = $request->getAttribute('frontend.page.information')
    • $id = $pageInformation->getId();
    • $fullRootLine = $pageInformation->getRootLine();
    • —> PageTsConfigFactory::create(array $fullRootLine, …)

    As every condition is based on the request, I don’t see why we should not add some more request-based condtions like colPos or languageId into Page TS-config.

    Technically the conditions are based on the request for e.g. new objects – as the new object itself has no data or non-request-based context at creation time.

  7. Oliver Bartsch commented <span data-processor="relativetime" data-value="2026-08-27T20:54:25+00:00" > 08/27/26, 20:54 </span>

    Hey,

    I agree with the close here, and will also add my reasoning why the “everything is
    request-based anyway” argument is not quite accurate.

    Provenance is not the same as semantics

    It is true that $pageUid usually arrives as $queryParams['id']. But the
    condition variables are not the request, they are the page and its rootline:
    persisted, addressable state. PageTsConfigFactory::create(array $fullRootLine,
    SiteInterface $site, ?UserTsConfig $userTsConfig)
    takes them as plain
    arguments, so any caller can reconstruct them from a page uid alone, in CLI, in
    an import, in a scheduler task, in a test fixture.

    defVals[tt_content][colPos] has no such existence. It lives inside exactly one
    form-rendering HTTP request and cannot be reconstructed anywhere else. That is
    the line #100047 drew, and it is a real one.

    The proposed example itself shows the problem

    The snippet above sets TCAdefaults.tt_content.layout = 601 inside the
    condition. TCAdefaults is consumed by the DataHandler:

    // DataHandler::newFieldArray()
    $tcaDefaults = BackendUtility::getPagesTSconfig($pageId)['TCAdefaults.'] ?? null;

    The DataHandler runs from CLI, from the scheduler, from imports and from
    extension code, and it knows nothing about defVals. TCEMAIN.* is read the
    same way in five further places. So this exact TSconfig would silently produce
    different records depending on the entry point, which is precisely the design
    flaw described in https://docs.typo3.org/permalink/changelog:deprecation-100047-1677608959.

    Caching

    BackendUtility::getPagesTSconfig() runtime-caches under
    @pageTsConfig-pid-to-hash-<pageuid>@, keyed by page uid alone. If the result<br>depended on a GET parameter, the first caller within a request would poison the<br>cached value for every later caller with a different colPos, for example when the<br>page module or a multi-record save touches several elements on one page.</pageuid>

    So: pageId being request-*supplied* is harmless exactly because the
    resulting TSconfig stays a pure function of (rootline, site, user).
    A colPos condition would make it a function of a transient URL parameter.

    The use case is legitimate, and there is a better answer

    “Field configuration depends on where the element sits” is a fair requirement,
    and the migration section of the deprecation does not really cover it. A
    FormDataProvider is not just the replacement, it is strictly better than the
    request condition ever was:

    • FormEngine is request-aware by contract, $result['request'] is guaranteed to
      be a ServerRequestInterface (see FormDataCompiler).
    • It does not even need the request.
      @DatabaseRowInitializeNew::setDefaultsFromDefaultValues()@ writes defVals
      into $result['databaseRow'], so a provider ordered after it simply reads
      @$result[‘databaseRow’][‘colPos’]@. For new records that is the defVal, for
      existing records the persisted value. One code path for both cases.
    • That makes the ttContentEdit() workaround unnecessary. It re-queries the
      database from $_GET['edit'] and only ever worked for existing records, never
      for new ones.
    • It stays display-only, which is what removeItems is, so the DataHandler can
      never disagree with what was shown in the form.

    If more is wanted

    If the actual wish is “TCEFORM depending on the record itself”, that is a
    feature request against TCEFORM / FormEngine rather than against TSconfig
    conditions. TCEFORM.<table>.<field>.types.<recordtype> already exists;
    generalising that towards other record fields would be evaluated where the
    record is known, instead of where only a URL is known. Happy to look at such a ticket.

    Best, Oli