'"Undeclared arguments passed to ViewHelper" Exception
After updating TYPO3, I get a TYPO3Fluid\Fluid\Core\ViewHelper\Exception
"Undeclared arguments passed to ViewHelper ... Valid arguments are."
Solution 1:[1]
Tip: Use rector to make these (and other) conversions! Functions for TYPO3 are available, see
This may be due to an extension using functionality that has been dropped. Using only the TYPO3 core, you should not see this error.
In your extension: If you still use the render() method in your ViewHelper class with arguments, you may want to replace this:
before:
public function render(Mail $mail, $type = 'web', $function = 'createAction')
after:
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('mail', Mail::class, 'Mail', true);
$this->registerArgument('type', 'string', 'type: web | mail', false, 'web');
$this->registerArgument('function', 'string', 'function: createAction | senderMail | receiverMail', false, 'createAction');
}
public function render()
{
$mail = $this->arguments['mail'];
$type = $this->arguments['type'] ?? 'web';
// ...
}
Additionally,
- if there is no need to use render() (e.g. unless you need to access $this variables), you may want to switch to renderStatic() for performance reasons (see also this other StackOverflow answer for clarification)
- inherit from classes in
TYPO3Fluid\Fluid\Core\ViewHelper
instead ofTYPO3\CMS\Fluid\Core\ViewHelper
:
// use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
Documentation:
Changelogs:
Solution 2:[2]
You are using other extension that makes this error, for example: https://github.com/lochmueller/calendarize/issues/280
If you have a parameters in a ViewHelper, you send them as arguments from Fluid Template. In TYPO3 this error throws when in render()
function not have comments about parameters. You have to include them.
Example:
<?php
namespace VENDOR\ExtensionName\ViewHelpers;
class ExampleViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
{
/**
*
* @param int $foo
* @return boolean
*/
public function render($foo) {
//function render lines
return $bar_boolean;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | César Dueñas |