Completed
Pull Request — master (#214)
by Claus
03:52
created

LayoutViewHelper::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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\Parser\SyntaxTree\ViewHelperNode;
10
use TYPO3Fluid\Fluid\Core\Variables\VariableProviderInterface;
11
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
12
use TYPO3Fluid\Fluid\Core\ViewHelper\PostParseInterface;
13
use TYPO3Fluid\Fluid\Core\ViewHelper\TemplateVariableContainer;
14
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileEmpty;
15
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\PassthroughRenderChildren;
16
17
/**
18
 * With this tag, you can select a layout to be used for the current template.
19
 *
20
 * = Examples =
21
 *
22
 * <code>
23
 * <f:layout name="main" />
24
 * </code>
25
 * <output>
26
 * (no output)
27
 * </output>
28
 *
29
 * @api
30
 */
31
class LayoutViewHelper extends AbstractViewHelper
32
{
33
    use CompileEmpty;
34
    use PassthroughRenderChildren;
35
36
    /**
37
     * Initialize arguments
38
     *
39
     * @return void
40
     * @api
41
     */
42
    public function initializeArguments()
43
    {
44
        $this->registerArgument('name', 'string', 'Name of layout to use. If none given, "Default" is used.');
45
    }
46
47
    /**
48
     * On the post parse event, add the "layoutName" variable to the variable container so it can be used by the TemplateView.
49
     *
50
     * @param ViewHelperNode $node
51
     * @param array $arguments
52
     * @param VariableProviderInterface $variableContainer
53
     * @return void
54
     */
55
    public static function postParseEvent(
56
        ViewHelperNode $node,
57
        array $arguments,
58
        VariableProviderInterface $variableContainer
59
    ) {
60
        if (isset($arguments['name'])) {
61
            $layoutNameNode = $arguments['name'];
62
        } else {
63
            $layoutNameNode = 'Default';
64
        }
65
66
        $variableContainer->add('layoutName', $layoutNameNode);
67
    }
68
}
69