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);
}
}
Michael
  • 645
  • 5
  • 12
MAZ
  • 222
  • 1
  • 14
  • Similar question exists: https://stackoverflow.com/questions/57274811/undeclared-arguments-passed-to-viewhelper-exception/57274812 – Sybille Peters Jun 25 '21 at 18:00

1 Answers1

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.

Michael
  • 645
  • 5
  • 12