Completed
Pull Request — master (#446)
by Claus
02:04
created

ElseViewHelper::initializeArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace TYPO3Fluid\Fluid\ViewHelpers;
3
4
/*
5
 * This file belongs to the package "TYPO3 Fluid".
6
 * See LICENSE.txt that was shipped with this package.
7
 */
8
9
use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
10
use TYPO3Fluid\Fluid\Core\Parser\NodeFilterInterface;
11
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\NodeInterface;
12
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\TextNode;
13
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
14
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
15
16
/**
17
 * Else-Branch of a condition. Only has an effect inside of "If". See the If-ViewHelper for documentation.
18
 *
19
 * = Examples =
20
 *
21
 * <code title="Output content if condition is not met">
22
 * <f:if condition="{someCondition}">
23
 *   <f:else>
24
 *     condition was not true
25
 *   </f:else>
26
 * </f:if>
27
 * </code>
28
 * <output>
29
 * Everything inside the "else" tag is displayed if the condition evaluates to FALSE.
30
 * Otherwise nothing is outputted in this example.
31
 * </output>
32
 *
33
 * @see TYPO3Fluid\Fluid\ViewHelpers\IfViewHelper
34
 * @api
35
 */
36
class ElseViewHelper extends AbstractViewHelper implements NodeFilterInterface
37
{
38
39
    /**
40
     * @var boolean
41
     */
42
    protected $escapeOutput = false;
43
44
    /**
45
     * @return void
46
     */
47
    public function initializeArguments()
48
    {
49
        $this->registerArgument('if', 'boolean', 'Condition expression conforming to Fluid boolean rules');
50
    }
51
52
    /**
53
     * @return string the rendered string
54
     * @api
55
     */
56
    public function render()
57
    {
58
        return $this->renderChildren();
59
    }
60
61
    /**
62
     * Condition ViewHelpers disallow child nodes that consist purely of whitespace,
63
     * thus avoiding whitespace in output inside f:if structures but not inside any
64
     * f:then or f:else nodes.
65
     *
66
     * @param NodeInterface $node
67
     * @return bool
68
     */
69 View Code Duplication
    public function allowsChildNodeType(NodeInterface $node): bool
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71
        if ($node instanceof TextNode && trim($node->getText()) === '') {
72
            return false;
73
        }
74
        return true;
75
    }
76
77
    /**
78
     * @param string $argumentsName
79
     * @param string $closureName
80
     * @param string $initializationPhpCode
81
     * @param ViewHelperNode $node
82
     * @param TemplateCompiler $compiler
83
     * @return string|NULL
84
     */
85
    public function compile($argumentsName, $closureName, &$initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler)
86
    {
87
        return '\'\'';
88
    }
89
}
90