0

I upgraded a website from TYPO3 v7 to v9 and now I get the following error:

Undeclared arguments passed to ViewHelper \ViewHelpers\MyViewHelper: value, list. Valid arguments are: [...]

My current ViewHelper looks as follows:

<?php

namespace VP\News\ViewHelpers;

/**
* @package TYPO3
* @subpackage Fluid
*/

class InListViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper  {

/**
* @param mixed $value value
* @param mixed $list list
* @return boolean
*/

public function render($value, $list) {
    if (!is_array($list)) {
        $list = str_replace(' ', '', $list);
        $list = explode(',', $list);
    }
    return in_array($value, $list);
}
}
1

1 Answer 1

2

Some things have changed between v7 and v9 ViewHelpers in TYPO3 Fluid.

➊ You should extend from the abstract class TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper.
➋ You have to register the arguments you pass to the ViewHelper.
➌ Your ViewHelper looks more like a Condition-ViewHelper than an Abstract-ViewHelper.

The first point is self-explanatory. Simply change the name of the base class (the fully qualified class name). For the second point, you can use an additional method initializeArguments(). For example:

public function initializeArguments(): void
{
  parent::initializeArguments();
  $this->registerArgument('value', 'type', 'description');
  ...
}

You can find an example here.

However, your ViewHelper seems to check a condition ("is this element in a list?", "then...", "else..."). Therefore, it might be better to implement a Condition-ViewHelper.

This type of ViewHelper extends the class TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper and evaluates a condition using a method verdict() instead of render() or renderStatic().

You can find an example of a simple Condition-ViewHelper here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.