[FEATURE] Show list of failed input fields in FormEngine
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid_styled_content / Classes / ViewHelpers / Menu / DirectoryViewHelper.php
1 <?php
2 namespace TYPO3\CMS\FluidStyledContent\ViewHelpers\Menu;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * A view helper which returns the subpages of the given pages
19 *
20 * = Example =
21 *
22 * <code title="Directory of pages with uid = 1 and uid = 2">
23 * <ce:menu.directory pageUids="{0: 1, 1: 2}" as="pages">
24 * <f:for each="{pages}" as="page">
25 * {page.title}
26 * </f:for>
27 * </ce:menu.directory>
28 * </code>
29 *
30 * <output>
31 * Subpage 1 of page with uid = 1
32 * Subpage 2 of page with uid = 1
33 * Subpage 1 of page with uid = 2
34 * </output>
35 */
36 class DirectoryViewHelper extends AbstractMenuViewHelper
37 {
38 /**
39 * Output escaping is disabled as child content contains HTML by default
40 *
41 * @var bool
42 */
43 protected $escapeOutput = false;
44
45 /**
46 * Initialize ViewHelper arguments
47 *
48 * @return void
49 */
50 public function initializeArguments()
51 {
52 $this->registerArgument('as', 'string', 'Name of template variable which will contain selected pages', true);
53 $this->registerArgument('levelAs', 'string', 'Name of template variable which will contain current level', false, null);
54 $this->registerArgument('pageUids', 'array', 'Page UIDs of parent pages', false, []);
55 $this->registerArgument('entryLevel', 'integer', 'The entry level', false, null);
56 $this->registerArgument('maximumLevel', 'integer', 'Maximum level for rendering of nested menus', false, 10);
57 $this->registerArgument('includeNotInMenu', 'boolean', 'Include pages that are marked "hide in menu"?', false, false);
58 $this->registerArgument('includeMenuSeparator', 'boolean', 'Include pages of the type "Menu separator"?', false, false);
59 }
60
61 /**
62 * Render the view helper
63 *
64 * @return string
65 */
66 public function render()
67 {
68 $typoScriptFrontendController = $this->getTypoScriptFrontendController();
69 $as = $this->arguments['as'];
70 $pageUids = (array)$this->arguments['pageUids'];
71 $entryLevel = $this->arguments['entryLevel'];
72 $levelAs = $this->arguments['levelAs'];
73 $maximumLevel = $this->arguments['maximumLevel'];
74 $includeNotInMenu = (bool)$this->arguments['includeNotInMenu'];
75 $includeMenuSeparator = (bool)$this->arguments['includeMenuSeparator'];
76
77 $pageUids = $this->getPageUids($pageUids, $entryLevel);
78 $pages = $typoScriptFrontendController->sys_page->getMenu(
79 $pageUids,
80 '*',
81 'sorting',
82 $this->getPageConstraints($includeNotInMenu, $includeMenuSeparator)
83 );
84
85 $output = '';
86
87 if (!empty($pages)) {
88 if (!$typoScriptFrontendController->register['ceMenuLevel_directory']) {
89 $typoScriptFrontendController->register['ceMenuLevel_directory'] = 1;
90 $typoScriptFrontendController->register['ceMenuMaximumLevel_directory'] = $maximumLevel;
91 } else {
92 $typoScriptFrontendController->register['ceMenuLevel_directory']++;
93 }
94
95 if ($typoScriptFrontendController->register['ceMenuLevel_directory'] > $typoScriptFrontendController->register['ceMenuMaximumLevel_directory']) {
96 return '';
97 }
98
99 $variables = [
100 $as => $pages
101 ];
102 if (!empty($levelAs)) {
103 $variables[$levelAs] = $typoScriptFrontendController->register['ceMenuLevel_directory'];
104 }
105 $output = $this->renderChildrenWithVariables($variables);
106
107 $typoScriptFrontendController->register['ceMenuLevel_directory']--;
108
109 if ($typoScriptFrontendController->register['ceMenuLevel_directory'] === 0) {
110 unset(
111 $typoScriptFrontendController->register['ceMenuLevel_directory'],
112 $typoScriptFrontendController->register['ceMenuMaximumLevel_directory']
113 );
114 }
115 }
116
117 return $output;
118 }
119 }