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