-
Notifications
You must be signed in to change notification settings - Fork 638
/
ActionMenuViewHelper.php
117 lines (109 loc) · 3.58 KB
/
ActionMenuViewHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Menus;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
/**
* View helper which returns a select box, that can be used to switch between
* multiple actions and controllers and looks similar to TYPO3s funcMenu.
* Note: This view helper is experimental!
*
* = Examples =
*
* <code title="Simple">
* <f:be.menus.actionMenu>
* <f:be.menus.actionMenuItem label="Overview" controller="Blog" action="index" />
* <f:be.menus.actionMenuItem label="Create new Blog" controller="Blog" action="new" />
* <f:be.menus.actionMenuItem label="List Posts" controller="Post" action="index" arguments="{blog: blog}" />
* </f:be.menus.actionMenu>
* </code>
* <output>
* Selectbox with the options "Overview", "Create new Blog" and "List Posts"
* </output>
*
* <code title="Localized">
* <f:be.menus.actionMenu>
* <f:be.menus.actionMenuItem label="{f:translate(key:'overview')}" controller="Blog" action="index" />
* <f:be.menus.actionMenuItem label="{f:translate(key:'create_blog')}" controller="Blog" action="new" />
* </f:be.menus.actionMenu>
* </code>
* <output>
* localized selectbox
* <output>
*/
class ActionMenuViewHelper extends AbstractTagBasedViewHelper
{
/**
* @var string
*/
protected $tagName = 'select';
/**
* An array of \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode
*
* @var array
*/
protected $childNodes = [];
/**
* Setter for ChildNodes - as defined in ChildNodeAccessInterface
*
* @param array $childNodes Child nodes of this syntax tree node
* @api
*/
public function setChildNodes(array $childNodes)
{
$this->childNodes = $childNodes;
}
/**
* Initialize arguments.
*
* @api
* @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('defaultController', 'string', 'defaultController');
}
/**
* Render FunctionMenu
*
* @return string
*/
public function render()
{
$this->tag->addAttribute('onchange', 'jumpToUrl(this.options[this.selectedIndex].value, this);');
$options = '';
foreach ($this->childNodes as $childNode) {
if ($childNode instanceof \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode) {
$options .= $childNode->evaluate($this->renderingContext);
}
}
$this->tag->setContent($options);
return '<div class="docheader-funcmenu">' . $this->tag->render() . '</div>';
}
/**
* @param string $argumentsName
* @param string $closureName
* @param string $initializationPhpCode
* @param ViewHelperNode $node
* @param TemplateCompiler $compiler
*/
public function compile($argumentsName, $closureName, &$initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler)
{
// @TODO: replace with a true compiling method to make compilable!
$compiler->disable();
return null;
}
}