vhs
vhs copied to clipboard
<v:asset.style/> makes the page crash : "count(): Parameter must be an array"
I uses the v:asset.style viewhelper to include my assets to my page, and this was working very well until I updated VHS from 6.1.2 => 6.1.3 Now, this viewhelper makes the page crash, and I got this error :
TYPO3\CMS\Core\Error\Exception
PHP Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/typo3/public/typo3conf/ext/vhs/Classes/Service/AssetService.php line 217
To reproduce, simply add these lines to your page :
<v:asset.style name="fontAwesome"
path="path/to/css/all.min.css"/>
Typo3 10.4.34 Php 7.4.11
I am not able to reproduce this problem.
I am even not sure I understand how this would be possible exclusively by using v:asset.style
:
- There are two cases in the code you reference - either the asset is an instance of AssetInterface, or it is not (in which case, it is almost certainly an array representation of an asset defined or modified in TypoScript, alternatively was created as a raw array through a third party usage of the VHS asset feature).
- In the case that it is an AssetInterface instance, getVariables() is strictly typed to only be capable of returning an array.
The error in question may be caused by something else - for example, another asset defined in TypoScript which has incorrectly defined the variables
as something other than an array, e.g. variables = some string
.
Either that, or I'm missing some additional context to help me reproduce this problem...
I have a similar problem (Typo3 11.5.37, VHS 6.1.3, PHP 8.2.18)
Javascript file is integrated via <v:asset.script path="xxx" name="NAME_X" movable="0" />. To correct the property "moveable" I wanted to change the assets settings via TypoScript plugin.tx_vhs.settings.asset.NAME_X {moveable = 1}.
The error is thrown under AssetService->placeAssetsInHeaderAndFooter. $asset instanceof AssetInterface is apparently not true. On the next line of code, $variables = $asset['variables'] ?? [] set to false. Another line later, the question count($variables) is asked. Of course this no longer works in PHP8 without Error Message. The problem persists until version VHS 7.0.3.
P.S. $asset['variables'] is declared as an optional property. P.S. Assets settings via TypoScript plugin.tx_vhs.settings.asset.NAME_X should reproduce this Problem.
Assuming that some method of defining TS is causing this - which is the only possible way I can think of that this could happen as all other variables sources are strictly typed - then commit #5e2f7f8 solves the problem.