TYPO3 CMS  TYPO3_7-6
DirectoryViewHelper.php
Go to the documentation of this file.
1 <?php
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 
18 
39 {
41 
47  public function initializeArguments()
48  {
49  $this->registerArgument('as', 'string', 'Name of template variable which will contain selected pages', true);
50  $this->registerArgument('levelAs', 'string', 'Name of template variable which will contain current level', false, null);
51  $this->registerArgument('pageUids', 'array', 'Page UIDs of parent pages', false, []);
52  $this->registerArgument('entryLevel', 'integer', 'The entry level', false, null);
53  $this->registerArgument('maximumLevel', 'integer', 'Maximum level for rendering of nested menus', false, 10);
54  $this->registerArgument('includeNotInMenu', 'boolean', 'Include pages that are marked "hide in menu"?', false, false);
55  $this->registerArgument('includeMenuSeparator', 'boolean', 'Include pages of the type "Menu separator"?', false, false);
56  }
57 
63  public function render()
64  {
65  $typoScriptFrontendController = $this->getTypoScriptFrontendController();
66  $as = $this->arguments['as'];
67  $pageUids = (array)$this->arguments['pageUids'];
68  $entryLevel = $this->arguments['entryLevel'];
69  $levelAs = $this->arguments['levelAs'];
70  $maximumLevel = $this->arguments['maximumLevel'];
71  $includeNotInMenu = (bool)$this->arguments['includeNotInMenu'];
72  $includeMenuSeparator = (bool)$this->arguments['includeMenuSeparator'];
73 
74  $pageUids = $this->getPageUids($pageUids, $entryLevel);
75  if (empty($pageUids)) {
76  return '';
77  }
78 
79  $pages = $typoScriptFrontendController->sys_page->getMenu(
80  $pageUids,
81  '*',
82  'sorting',
83  $this->getPageConstraints($includeNotInMenu, $includeMenuSeparator)
84  );
85 
86  $output = '';
87 
88  if (!empty($pages)) {
89  if (!$typoScriptFrontendController->register['ceMenuLevel_directory']) {
90  $typoScriptFrontendController->register['ceMenuLevel_directory'] = 1;
91  $typoScriptFrontendController->register['ceMenuMaximumLevel_directory'] = $maximumLevel;
92  } else {
93  $typoScriptFrontendController->register['ceMenuLevel_directory']++;
94  }
95 
96  if ($typoScriptFrontendController->register['ceMenuLevel_directory'] > $typoScriptFrontendController->register['ceMenuMaximumLevel_directory']) {
97  return '';
98  }
99 
100  $variables = [
101  $as => $pages
102  ];
103  if (!empty($levelAs)) {
104  $variables[$levelAs] = $typoScriptFrontendController->register['ceMenuLevel_directory'];
105  }
106  $output = $this->renderChildrenWithVariables($variables);
107 
108  $typoScriptFrontendController->register['ceMenuLevel_directory']--;
109 
110  if ($typoScriptFrontendController->register['ceMenuLevel_directory'] === 0) {
111  unset($typoScriptFrontendController->register['ceMenuLevel_directory']);
112  unset($typoScriptFrontendController->register['ceMenuMaximumLevel_directory']);
113  }
114  }
115 
116  return $output;
117  }
118 }
registerArgument($name, $type, $description, $required=false, $defaultValue=null)