TYPO3  7.6
UpdatedViewHelper.php
Go to the documentation of this file.
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 
18 
39 {
40  use MenuViewHelperTrait;
41 
47  public function initializeArguments()
48  {
49  $this->registerArgument('as', 'string', 'Name of the template variable that will contain selected pages', true);
50  $this->registerArgument('pageUids', 'array', 'Page UIDs of parent pages', false, array());
51  $this->registerArgument('sortField', 'string', 'Field to sort pages; possible values: starttime, lastUpdated, tstamp, crdate', false, 'SYS_LASTCHANGED');
52  $this->registerArgument('maximumAge', 'string', 'Maximum age of pages to be included; supports mathematical expressions', false, '604800');
53  $this->registerArgument('includeNotInMenu', 'boolean', 'Include pages that are marked "hide in menu"?', false, false);
54  $this->registerArgument('includeMenuSeparator', 'boolean', 'Include pages of the type "Menu separator"?', false, false);
55  $this->registerArgument('excludeNoSearchPages', 'boolean', 'Exclude pages that are NOT marked "include in search"?', false, true);
56  }
57 
63  public function render()
64  {
65  $typoScriptFrontendController = $this->getTypoScriptFrontendController();
66  $as = (string)$this->arguments['as'];
67  $pageUids = (array)$this->arguments['pageUids'];
68  $sortField = $this->arguments['sortField'];
69  $maximumAge = $this->arguments['maximumAge'];
70  $includeNotInMenu = (bool)$this->arguments['includeNotInMenu'];
71  $includeMenuSeparator = (bool)$this->arguments['includeMenuSeparator'];
72  $excludeNoSearchPages = (bool)$this->arguments['excludeNoSearchPages'];
73 
74  // If no pages have been defined, use the current page
75  if (empty($pageUids)) {
76  $pageUids = array($typoScriptFrontendController->page['uid']);
77  }
78 
79  $unfilteredPageTreeUids = array();
80  foreach ($pageUids as $pageUid) {
81  $unfilteredPageTreeUids = array_merge(
82  $unfilteredPageTreeUids,
83  explode(
84  ',',
85  $typoScriptFrontendController->cObj->getTreeList($pageUid, 20)
86  )
87  );
88  }
89  $pageTreeUids = array_unique($unfilteredPageTreeUids);
90 
91  $constraints = $this->getPageConstraints($includeNotInMenu, $includeMenuSeparator);
92 
93  if ($excludeNoSearchPages) {
94  $constraints .= ' AND no_search = 0';
95  }
96 
97  if (!in_array($sortField, ['starttime', 'lastUpdated', 'tstamp', 'crdate'])) {
98  $sortField = 'SYS_LASTCHANGED';
99  }
100 
101  $minimumTimeStamp = time() - (int)$typoScriptFrontendController->cObj->calc($maximumAge);
102  $constraints .= ' AND ' . $sortField . ' >=' . $minimumTimeStamp;
103 
104  $pages = $typoScriptFrontendController->sys_page->getMenuForPages(
105  $pageTreeUids,
106  '*',
107  $sortField . ' DESC',
108  $constraints
109  );
110  return $this->renderChildrenWithVariables(array(
111  $as => $pages
112  ));
113  }
114 }