[SOLVED] AbstractConditionViewHelper does not work

Hello flow developers!

I’ve just ran into trouble on implementing an AbstractConditionViewHelper.

My implementation looks like this:

class IsEditableViewHelper extends AbstractConditionViewHelper
     * @param MyObject $myObject

    public function render( MyObject $myObject )
        if ( ( $myObject->getPropA() == "foo" ) || ( $myObject->getPropA() == "bar" ) )
            return $this->renderThenChild();
            return $this->renderElseChild();
    } // public function render

And in template:

<mstate:IsEditable myObject="{objectToTest}"><f:then>yes</f:then><f:else>no</f:else></mstate:IsEditable>

This works exactly one time after editing IsEditableViewHelper.php file.
Afterwards (reload page in browser with same object(s)) always the elseChild is rendered.

Info: flow version 5.2.3

Whats wrong with that? Any suggestions?

Hey Frank,

the issue here is, that the ViewHelper will be compiled by Fluid (because AbstractConditionViewHelper is compileable) and the render method will not be called directly any more after the first invocation. The solution is simple though:

You need to implement the static method verdict OR evaluateCondition (the old way, still there for b/c):

Inside that method, you put the conditional logic depending on the $arguments array (and possibly the RenderingContext inside verdict). Everything else will be handled by Fluid then.

1 Like

Hello Alexander!

Ah, I see. Okay …
Your hint explains my observation.

Thanks a lot for your help!!!
I’ve just want to set up a debugging session, which I don’t need now…