/
DirectoryViewHelper.php
61 lines (57 loc) · 1.75 KB
/
DirectoryViewHelper.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
<?php
namespace FluidTYPO3\Vhs\ViewHelpers\Menu;
/*
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
/**
* ### Page: Directory Menu ViewHelper
*
* ViewHelper for rendering TYPO3 list menus in Fluid
*
* Supports both automatic, tag-based rendering (which
* defaults to `ul > li` with options to set both the
* parent and child tag names. When using manual rendering
* a range of support CSS classes are available along
* with each page record.
*/
class DirectoryViewHelper extends AbstractMenuViewHelper
{
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument(
'pages',
'mixed',
'Parent page UIDs of subpages to include in the menu. Can be CSV, array or an object ' .
'implementing Traversable.',
true
);
}
/**
* @return null|string
*/
public function render()
{
$pages = $this->processPagesArgument();
if (0 === count($pages)) {
return null;
}
$menuData = [];
foreach ($pages as $pageUid) {
$menuData = array_merge($menuData, $this->getMenu($pageUid));
}
$menu = $this->parseMenu($menuData);
$this->backupVariables();
$variableProvider = $this->renderingContext->getVariableProvider();
/** @var string $as */
$as = $this->arguments['as'];
$variableProvider->add($as, $menu);
$output = $this->renderContent($menu);
$variableProvider->remove($as);
$this->restoreVariables();
return $output;
}
}