neos / flow-development-collection

The unified repository containing the Flow core packages, used for Flow development.
https://flow.neos.io/
MIT License
139 stars 188 forks source link

Custom Conditional ViewHelper and renderStatic #1242

Open BlitzInternet opened 6 years ago

BlitzInternet commented 6 years ago

Description

For once I'm not sure if this is a bug or if the manual is not up-to-date. http://flowframework.readthedocs.io/en/4.3/TheDefinitiveGuide/PartIII/Templating.html#abstractconditionviewhelper

There is no mention of the need to implement renderStatic. When I migrated the first project to flow 4.3 I started seeing problems with all my custom conditional viewhelpers, ie. any that extended \Neos\FluidAdaptor\Core\ViewHelper\AbstractConditionViewHelper

They were rendering on the first call, and then never again. Digging into the code it turns out that not overriding the renderStatic method caused this. There is no mention of this in the manual!

I worked around it by creating my own AbstractConditionViewHelper (extending the same class the original one did) and removing all static methods. Things worked for the last month, but now in v4.3.3, new problems popped up and I can't tell why all of a sudden.

Apparently extending TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper in ANY WAY causes this to render empty, since this class now has an empty renderStatic method.

It should go without saying that I cannot use static methods in most viewhelpers so this is not an option.

Please document a way to create your own ViewHelpers that do not require any static methods!

Steps to Reproduce

  1. create your own viewhelper extending \Neos\FluidAdaptor\Core\ViewHelper\AbstractConditionViewHelper
  2. only implement render() method, no static methods
  3. render page at least twice

Expected behavior

view helper then or else is still rendered upon second rendering

Actual behavior

else is always rendered starting from second rendering because lack of implemented renderStatic methods

Affected Versions

neos/flow 4.3.3 neos/fluid-adaptor 4.3.3 typo3fluid/fluid 2.1.3

albe commented 6 years ago

Indeed the manual is outdated there. The correct implementation for a condition ViewHelper (since the shift to Standalone Fluid with 4.0) is explained in the docblock of the abstract class only. Needs to be fixed, so thanks for the hint. Keeping docs in sync is sometimes not so easy.

Not sure why things changed again with 4.3.3, I can only guess that something inside Typo3fluid changed.