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