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