Issue Bug Closed

#100338TypeError due to missing type cast on pageUid in TYPO3\CMS\Fluid\ViewHelpers\Uri\ActionViewHelper

Andreas Radermeker 03/28/23, 13:26 updated 07/09/24, 12:55

Description

Hi,
we found an issue in class “TYPO3\CMS\Fluid\ViewHelpers\Uri\ActionViewHelper”, method “renderStatic” on line number 77. The argument “pageUid” is used and causes an error in PHP 8.1 due to a missing type cast to integer.
As the UriBuilder requires the parameter for “setTargetPageUid()” to be an integer, the fix could be to add a type cast (int) like its done in any other ViewHelper class using a “pageUid”.

The error can be reproduced by using an integer value from the settings array in fluid or by using a cObject type TEXT with a numeric value and pass it to the ViewHelper used in a plugin template (eg. EXT:felogin):

{f:uri.action(pageUid: '{f:cObject(typoscriptObjectPath: \'PAGEUID\')}', action: 'Action', controller: 'Controller', pluginName:'PluginName', extensionName: 'ExtensionName')}

OR

{f:uri.action(pageUid: '{settings.PAGEUID}', action: 'Action', controller: 'Controller', pluginName:'PluginName', extensionName: 'ExtensionName')}

Following solution could be applied:
Change

/** @var int $pageType */
$pageType = $arguments['pageType'] ?? 0;

to

/** @var int $pageType */
$pageType = (int)$arguments['pageType'] ?? 0;

Actual Result: We are getting a TypeError:

TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder::setTargetPageUid(): Argument #1 ($targetPageUid) must be of type int, string given, called in /var/www/source-files/typo3_src-12.3.0/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ActionViewHelper.php on line 111

Expected Result: Getting an uri from from the viewhelper like “https://example.com/test?tx_extensionname_pluginname%5Baction%5D=Action&tx_extensionname_pluginname%5Bcontroller%5D=Controller&cHash=dbf5ada008ba1673f519e3248a13a434”

Additional notes:
*We reproduced the error in TYPO3 11LTS running on PHP 8.1 aswell*

Thank you!

Reviews 3