TYPO3 CMS  TYPO3_7-6
TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper Class Reference
Inheritance diagram for TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper:
TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper TYPO3\CMS\Fluid\Core\ViewHelper\Facets\ChildNodeAccessInterface TYPO3\CMS\Fluid\ViewHelpers\Be\Security\IfAuthenticatedViewHelper TYPO3\CMS\Fluid\ViewHelpers\Be\Security\IfHasRoleViewHelper TYPO3\CMS\Fluid\ViewHelpers\IfViewHelper TYPO3\CMS\Fluid\ViewHelpers\Security\IfAuthenticatedViewHelper TYPO3\CMS\Fluid\ViewHelpers\Security\IfHasRoleViewHelper

Public Member Functions

 setChildNodes (array $childNodes)
 
 __construct ()
 
 render ()
 
 compile ($argumentsVariableName, $renderChildrenClosureVariableName, &$initializationPhpCode, \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode $syntaxTreeNode, \TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler $templateCompiler)
 
- Public Member Functions inherited from TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
 setArguments (array $arguments)
 
 setRenderingContext (\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
 
 injectObjectManager (\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
 
 injectReflectionService (\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService)
 
 isEscapingInterceptorEnabled ()
 
 setViewHelperNode (\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode $node)
 
 setRenderChildrenClosure (\Closure $renderChildrenClosure)
 
 initializeArgumentsAndRender ()
 
 initialize ()
 
 renderChildren ()
 
 prepareArguments ()
 
 validateArguments ()
 
 initializeArguments ()
 
 compile ($argumentsVariableName, $renderChildrenClosureVariableName, &$initializationPhpCode, \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode $syntaxTreeNode, \TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler $templateCompiler)
 
 resetState ()
 

Static Public Member Functions

static renderStatic (array $arguments, \Closure $renderChildrenClosure, \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
 
- Static Public Member Functions inherited from TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
static renderStatic (array $arguments, \Closure $renderChildrenClosure, \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
 

Protected Member Functions

 renderThenChild ()
 
 renderElseChild ()
 
- Protected Member Functions inherited from TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
 registerArgument ($name, $type, $description, $required=false, $defaultValue=null)
 
 overrideArgument ($name, $type, $description, $required=false, $defaultValue=null)
 
 callRenderMethod ()
 
 getLogger ()
 
 buildRenderChildrenClosure ()
 
 hasArgument ($argumentName)
 

Static Protected Member Functions

static renderStaticThenChild ($arguments, &$hasEvaluated)
 
static renderStaticElseChild ($arguments, &$hasEvaluated)
 
static evaluateCondition ($arguments=null)
 

Private Attributes

 $childNodes = []
 

Additional Inherited Members

- Protected Attributes inherited from TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
 $arguments
 
 $templateVariableContainer
 
 $controllerContext
 
 $renderingContext
 
 $renderChildrenClosure = null
 
 $viewHelperVariableContainer
 
 $objectManager
 
 $escapingInterceptorEnabled = true
 

Detailed Description

This view helper is an abstract ViewHelper which implements an if/else condition.

= Usage =

To create a custom Condition ViewHelper, you need to subclass this class, and implement your own render() method. Inside there, you should call $this->renderThenChild() if the condition evaluated to TRUE, and $this->renderElseChild() if the condition evaluated to FALSE.

Every Condition ViewHelper has a "then" and "else" argument, so it can be used like: <[aConditionViewHelperName] .... then="condition true" else="condition false" />, or as well use the "then" and "else" child nodes.

See also
TYPO3 for a more detailed explanation and a simple usage example. Make sure to NOT OVERRIDE the constructor.

Definition at line 37 of file AbstractConditionViewHelper.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper::__construct ( )

Initializes the "then" and "else" arguments

Definition at line 60 of file AbstractConditionViewHelper.php.

References TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper\registerArgument().

Member Function Documentation

◆ compile()

TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper::compile (   $argumentsVariableName,
  $renderChildrenClosureVariableName,
$initializationPhpCode,
\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode  $syntaxTreeNode,
\TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler  $templateCompiler 
)

The compiled ViewHelper adds two new ViewHelper arguments: __thenClosure and __elseClosure. These contain closures which are be executed to render the then(), respectively else() case.

Parameters
string$argumentsVariableName
string$renderChildrenClosureVariableName
string$initializationPhpCode
\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode$syntaxTreeNode
\TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler$templateCompiler
Returns
string

Definition at line 199 of file AbstractConditionViewHelper.php.

References TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode\getViewHelperClassName().

◆ evaluateCondition()

static TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper::evaluateCondition (   $arguments = null)
staticprotected

This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.

Parameters
array$argumentsViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
Returns
bool

Definition at line 254 of file AbstractConditionViewHelper.php.

References TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper\$arguments.

◆ render()

TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper::render ( )

renders <f:then> child if $condition is true, otherwise renders <f:else> child.

Returns
string the rendered string

Definition at line 72 of file AbstractConditionViewHelper.php.

References TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper\renderElseChild(), and TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper\renderThenChild().

◆ renderElseChild()

TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper::renderElseChild ( )
protected

Returns value of "else" attribute. If else attribute is not set, iterates through child nodes and renders ElseViewHelper. If else attribute is not set and no ElseViewHelper is found, an empty string will be returned.

Returns
string rendered ElseViewHelper or an empty string if no ThenViewHelper was found

Definition at line 148 of file AbstractConditionViewHelper.php.

References TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode\getViewHelperClassName().

Referenced by TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper\render().

◆ renderStatic()

static TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper::renderStatic ( array  $arguments,
\Closure  $renderChildrenClosure,
\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface  $renderingContext 
)
static

Default implementation for CompilableInterface. See CompilableInterface for a detailed description of this method.

Parameters
array$arguments
\Closure$renderChildrenClosure
\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface$renderingContext
Returns
mixed
See also

Definition at line 228 of file AbstractConditionViewHelper.php.

References TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper\$renderChildrenClosure.

◆ renderStaticElseChild()

static TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper::renderStaticElseChild (   $arguments,
$hasEvaluated 
)
staticprotected

Statically evalute "else" children. The "$hasEvaluated" argument is there to distinguish the case that "else" returned NULL or was not evaluated.

Parameters
array$argumentsViewHelper arguments
bool$hasEvaluatedCan be used to check if the "else" child was actually evaluated by this method.
Returns
string

Definition at line 174 of file AbstractConditionViewHelper.php.

References TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper\$arguments.

◆ renderStaticThenChild()

static TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper::renderStaticThenChild (   $arguments,
$hasEvaluated 
)
staticprotected

Statically evalute "then" children. The "$hasEvaluated" argument is there to distinguish the case that "then" returned NULL or was not evaluated.

Parameters
array$argumentsViewHelper arguments
bool$hasEvaluatedCan be used to check if the "then" child was actually evaluated by this method.
Returns
string

Definition at line 125 of file AbstractConditionViewHelper.php.

References TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper\$arguments.

◆ renderThenChild()

TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper::renderThenChild ( )
protected

Returns value of "then" attribute. If then attribute is not set, iterates through child nodes and renders ThenViewHelper. If then attribute is not set and no ThenViewHelper and no ElseViewHelper is found, all child nodes are rendered

Returns
string rendered ThenViewHelper or contents of <f:if> if no ThenViewHelper was found

Definition at line 89 of file AbstractConditionViewHelper.php.

References TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode\getViewHelperClassName(), and TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper\renderChildren().

Referenced by TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper\render().

◆ setChildNodes()

TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper::setChildNodes ( array  $childNodes)

Setter for ChildNodes - as defined in ChildNodeAccessInterface

Parameters
array$childNodesChild nodes of this syntax tree node
Returns
void

Implements TYPO3\CMS\Fluid\Core\ViewHelper\Facets\ChildNodeAccessInterface.

Definition at line 52 of file AbstractConditionViewHelper.php.

References TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper\$childNodes.

Member Data Documentation

◆ $childNodes

TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper::$childNodes = []
private