Skip to content

Resolve cObject variables in per-file includeCSS blocks (v13 backport) - #106

Open
svewap wants to merge 1 commit into
release/v13from
fix/scss-cobject-variables-per-file
Open

svewap wants to merge 1 commit into
release/v13from
fix/scss-cobject-variables-per-file

Conversation

@svewap

@svewap svewap commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Backport of the first half of #105 to release/v13. The v13 branch has the same bug: only the global plugin.tx_wsscss.variables path resolved content objects, while the per-file page.includeCSS.<key>.variables block took the TypoScript array verbatim (array_filter($subConf['variables.'] ?? []), line 140).

A cObject variable (myVar = TEXT + myVar.value = …) therefore kept its myVar. sub-array, which reached Compiler::compileFile() and hit implode(',', $variables):

PHP Warning: Array to string conversion in …/ws-scss/Classes/Compiler.php line 82

TYPO3's error handler turns that into an exception → HTTP 500 in the frontend. It is easy to hit, because copying the global block per file is the documented way to scope variables to a single file, and t3bootstrap does exactly that.

Both paths now share parseTypoScriptVariables().

Not backported: the setRequest() part of #105. ContentObjectRenderer::getRequest() still has an undeprecated $GLOBALS['TYPO3_REQUEST'] fallback in v13 (only a @todo in core), so that change has no effect here and is left out to keep the diff minimal.

Verification

TYPO3 13.4.29-dev, PHP 8.4.20, scssphp 2.1.0. Driving renderPreProcessorProc() with a per-file block containing cobj-test = TEXT / .value = 3px, a nested COA (10 = TEXT/10.value = 7, 20 = TEXT/20.value = px) and a plain 11px:

before

THROWN: TYPO3\CMS\Core\Error\Exception
  PHP Warning: Array to string conversion in …/ws-scss/Classes/Compiler.php line 82

after

.probe {
  padding: 3px;
  margin: 7px;
  gap: 11px;
}

No regression on the setups that already worked — global block, per-file plain values, and global cObject all compile to byte-identical CSS with and without the patch (md5=9222d0fbf812c3ec0f495bea1360b9db in all six runs).

Only the global `plugin.tx_wsscss.variables` path resolved content objects.
The per-file `page.includeCSS.<key>.variables` block took the TypoScript array
verbatim, so a cObject variable (`myVar = TEXT` + `myVar.value = …`) kept its
`myVar.` sub-array. That nested array reached Compiler::compileFile(), where
`implode(',', $variables)` raised an "Array to string conversion" warning --
turned into an exception by TYPO3's error handler, i.e. a 500 in the frontend.

This is easy to hit, because copying the global block per file
(`variables < plugin.tx_wsscss.variables`) is the documented way to pass
variables to a single file, and t3bootstrap does exactly that.

Both paths now share parseTypoScriptVariables(), which renders content objects
and drops leftover sub-arrays.

Verified on TYPO3 13.4.29 / PHP 8.4.20: before the change a per-file cObject
variable throws at Compiler.php:82, after it `myVar = TEXT` + `.value = 3px`
and a nested COA both resolve to plain strings. The three setups that already
worked (global block, per-file plain values, global cObject) compile to
byte-identical CSS.

Backport of the first half of the v14 fix; the setRequest() part of that change
does not apply here, because ContentObjectRenderer::getRequest() has no
deprecated fallback in v13.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant