[TASK] Deprecate MenuViewHelperTrait
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid_styled_content / Classes / ViewHelpers / Menu / AbstractMenuViewHelper.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 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
18 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
19 use TYPO3\CMS\Frontend\Page\PageRepository;
20
21 /**
22 * Class AbstractMenuViewHelper
23 */
24 abstract class AbstractMenuViewHelper extends AbstractViewHelper
25 {
26 /**
27 * Get the constraints for the page based on doktype and field "nav_hide"
28 *
29 * By default the following doktypes are always ignored:
30 * - 6: Backend User Section
31 * - > 200: Folder (254)
32 * Recycler (255)
33 *
34 * Optional are:
35 * - 199: Menu separator
36 * - nav_hide: Not in menu
37 *
38 * @param bool $includeNotInMenu Should pages which are hidden for menu's be included
39 * @param bool $includeMenuSeparator Should pages of type "Menu separator" be included
40 * @return string
41 */
42 protected function getPageConstraints($includeNotInMenu = false, $includeMenuSeparator = false)
43 {
44 $constraints = array();
45
46 $constraints[] = 'doktype NOT IN (' . PageRepository::DOKTYPE_BE_USER_SECTION . ',' . PageRepository::DOKTYPE_RECYCLER . ',' . PageRepository::DOKTYPE_SYSFOLDER . ')';
47
48 if (!$includeNotInMenu) {
49 $constraints[] = 'nav_hide = 0';
50 }
51
52 if (!$includeMenuSeparator) {
53 $constraints[] = 'doktype != ' . PageRepository::DOKTYPE_SPACER;
54 }
55
56 return 'AND ' . implode(' AND ', $constraints);
57 }
58
59 /**
60 * Get a filtered list of page UIDs according to initial list
61 * of UIDs and entryLevel parameter.
62 *
63 * @param array $pageUids
64 * @param int|null $entryLevel
65 * @return array
66 */
67 protected function getPageUids(array $pageUids, $entryLevel = 0)
68 {
69 $typoScriptFrontendController = $this->getTypoScriptFrontendController();
70
71 // Remove empty entries from array
72 $pageUids = array_filter($pageUids);
73
74 // If no pages have been defined, use the current page
75 if (empty($pageUids)) {
76 if ($entryLevel !== null) {
77 if ($entryLevel < 0) {
78 $entryLevel = count($typoScriptFrontendController->tmpl->rootLine) - 1 + $entryLevel;
79 }
80 $pageUids = array($typoScriptFrontendController->tmpl->rootLine[$entryLevel]['uid']);
81 } else {
82 $pageUids = array($typoScriptFrontendController->id);
83 }
84 }
85
86 return $pageUids;
87 }
88
89 /**
90 * @param array $variables
91 * @return mixed
92 */
93 protected function renderChildrenWithVariables(array $variables)
94 {
95 foreach ($variables as $name => $value) {
96 $this->templateVariableContainer->add($name, $value);
97 }
98
99 $output = $this->renderChildren();
100
101 foreach ($variables as $name => $_) {
102 $this->templateVariableContainer->remove($name);
103 }
104
105 return $output;
106 }
107
108 /**
109 * @return TypoScriptFrontendController
110 */
111 protected function getTypoScriptFrontendController()
112 {
113 return $GLOBALS['TSFE'];
114 }
115 }