diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-75209-CodecleanupForMenuViewHelperTrait.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-75209-CodecleanupForMenuViewHelperTrait.rst new file mode 100644 index 0000000000000000000000000000000000000000..0e5e84637eaa698fd5840bde87a19c8a790b05a9 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-75209-CodecleanupForMenuViewHelperTrait.rst @@ -0,0 +1,27 @@ +========================================================== +Deprecation: #75209 - Code cleanup for MenuViewHelperTrait +========================================================== + +Description +=========== + +The ``MenuViewHelperTrait`` has been marked as deprecated. +All methods of the Trait have been implemented in a new ``AbstractMenuViewHelper`` class. + + +Impact +====== + +Using the methods of the ``MenuViewHelperTrait`` will trigger a deprecation log entry. + + +Affected Installations +====================== + +Instances with custom extensions that use the ``MenuViewHelperTrait`. + + +Migration +========= + +Extend the new ``AbstractMenuViewHelper`` which contains all methods instead of using the trait. diff --git a/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/AbstractMenuViewHelper.php b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/AbstractMenuViewHelper.php new file mode 100644 index 0000000000000000000000000000000000000000..f53b13aada6a0670aec74408b44ec1bcbf62ea74 --- /dev/null +++ b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/AbstractMenuViewHelper.php @@ -0,0 +1,115 @@ +<?php +namespace TYPO3\CMS\FluidStyledContent\ViewHelpers\Menu; + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper; +use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; +use TYPO3\CMS\Frontend\Page\PageRepository; + +/** + * Class AbstractMenuViewHelper + */ +abstract class AbstractMenuViewHelper extends AbstractViewHelper +{ + /** + * Get the constraints for the page based on doktype and field "nav_hide" + * + * By default the following doktypes are always ignored: + * - 6: Backend User Section + * - > 200: Folder (254) + * Recycler (255) + * + * Optional are: + * - 199: Menu separator + * - nav_hide: Not in menu + * + * @param bool $includeNotInMenu Should pages which are hidden for menu's be included + * @param bool $includeMenuSeparator Should pages of type "Menu separator" be included + * @return string + */ + protected function getPageConstraints($includeNotInMenu = false, $includeMenuSeparator = false) + { + $constraints = array(); + + $constraints[] = 'doktype NOT IN (' . PageRepository::DOKTYPE_BE_USER_SECTION . ',' . PageRepository::DOKTYPE_RECYCLER . ',' . PageRepository::DOKTYPE_SYSFOLDER . ')'; + + if (!$includeNotInMenu) { + $constraints[] = 'nav_hide = 0'; + } + + if (!$includeMenuSeparator) { + $constraints[] = 'doktype != ' . PageRepository::DOKTYPE_SPACER; + } + + return 'AND ' . implode(' AND ', $constraints); + } + + /** + * Get a filtered list of page UIDs according to initial list + * of UIDs and entryLevel parameter. + * + * @param array $pageUids + * @param int|null $entryLevel + * @return array + */ + protected function getPageUids(array $pageUids, $entryLevel = 0) + { + $typoScriptFrontendController = $this->getTypoScriptFrontendController(); + + // Remove empty entries from array + $pageUids = array_filter($pageUids); + + // If no pages have been defined, use the current page + if (empty($pageUids)) { + if ($entryLevel !== null) { + if ($entryLevel < 0) { + $entryLevel = count($typoScriptFrontendController->tmpl->rootLine) - 1 + $entryLevel; + } + $pageUids = array($typoScriptFrontendController->tmpl->rootLine[$entryLevel]['uid']); + } else { + $pageUids = array($typoScriptFrontendController->id); + } + } + + return $pageUids; + } + + /** + * @param array $variables + * @return mixed + */ + protected function renderChildrenWithVariables(array $variables) + { + foreach ($variables as $name => $value) { + $this->templateVariableContainer->add($name, $value); + } + + $output = $this->renderChildren(); + + foreach ($variables as $name => $_) { + $this->templateVariableContainer->remove($name); + } + + return $output; + } + + /** + * @return TypoScriptFrontendController + */ + protected function getTypoScriptFrontendController() + { + return $GLOBALS['TSFE']; + } +} diff --git a/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/CategoriesViewHelper.php b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/CategoriesViewHelper.php index 5e4311ec4fceede2e0d325366a8c9c151ffd5b16..402f063e491dabb6d70d02711e49b084afe13199 100644 --- a/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/CategoriesViewHelper.php +++ b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/CategoriesViewHelper.php @@ -14,7 +14,6 @@ namespace TYPO3\CMS\FluidStyledContent\ViewHelpers\Menu; * The TYPO3 project - inspiring people to share! */ -use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper; use TYPO3\CMS\Fluid\Core\ViewHelper\Exception; use TYPO3\CMS\Frontend\Category\Collection\CategoryCollection; @@ -36,10 +35,8 @@ use TYPO3\CMS\Frontend\Category\Collection\CategoryCollection; * Page with category 1 and 2 assigned * </output> */ -class CategoriesViewHelper extends AbstractViewHelper +class CategoriesViewHelper extends AbstractMenuViewHelper { - use MenuViewHelperTrait; - /** * Output escaping is disabled as child content contains HTML by default * diff --git a/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/DirectoryViewHelper.php b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/DirectoryViewHelper.php index e8c02ae9004f8a0808734c1575cbfb84a98b5d71..ee926a194a8063ef519378dbb8b59dcb34cda8b9 100644 --- a/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/DirectoryViewHelper.php +++ b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/DirectoryViewHelper.php @@ -14,8 +14,6 @@ namespace TYPO3\CMS\FluidStyledContent\ViewHelpers\Menu; * The TYPO3 project - inspiring people to share! */ -use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper; - /** * A view helper which returns the subpages of the given pages * @@ -35,10 +33,8 @@ use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper; * Subpage 1 of page with uid = 2 * </output> */ -class DirectoryViewHelper extends AbstractViewHelper +class DirectoryViewHelper extends AbstractMenuViewHelper { - use MenuViewHelperTrait; - /** * Output escaping is disabled as child content contains HTML by default * @@ -111,8 +107,10 @@ class DirectoryViewHelper extends AbstractViewHelper $typoScriptFrontendController->register['ceMenuLevel_directory']--; if ($typoScriptFrontendController->register['ceMenuLevel_directory'] === 0) { - unset($typoScriptFrontendController->register['ceMenuLevel_directory']); - unset($typoScriptFrontendController->register['ceMenuMaximumLevel_directory']); + unset( + $typoScriptFrontendController->register['ceMenuLevel_directory'], + $typoScriptFrontendController->register['ceMenuMaximumLevel_directory'] + ); } } diff --git a/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/KeywordsViewHelper.php b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/KeywordsViewHelper.php index 855131cbd7def53aa469c2b97f2151e42f7808bf..fd523ee5f3b68187c5952d943e1f9bb4af925e54 100644 --- a/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/KeywordsViewHelper.php +++ b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/KeywordsViewHelper.php @@ -14,7 +14,6 @@ namespace TYPO3\CMS\FluidStyledContent\ViewHelpers\Menu; * The TYPO3 project - inspiring people to share! */ use TYPO3\CMS\Core\Database\DatabaseConnection; -use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper; /** * A view helper which returns pages with one of the same keywords as the given pages @@ -38,9 +37,8 @@ use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper; * Page with the keyword "typo3" * </output> */ -class KeywordsViewHelper extends AbstractViewHelper +class KeywordsViewHelper extends AbstractMenuViewHelper { - use MenuViewHelperTrait; /** * Output escaping is disabled as child content contains HTML by default diff --git a/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/ListViewHelper.php b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/ListViewHelper.php index b7c5b2977588be903746aca754950c8f78cb4bbb..85cfaf56dd4cd81fd87d913b39bf899d7772774d 100644 --- a/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/ListViewHelper.php +++ b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/ListViewHelper.php @@ -13,7 +13,6 @@ namespace TYPO3\CMS\FluidStyledContent\ViewHelpers\Menu; * * The TYPO3 project - inspiring people to share! */ -use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper; /** * A view helper which returns a list of pages @@ -33,13 +32,11 @@ use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper; * Page with uid = 2 * </output> */ -class ListViewHelper extends AbstractViewHelper +class ListViewHelper extends AbstractMenuViewHelper { - use MenuViewHelperTrait; - /** * Output escaping is disabled as child content contains HTML by default - * + * * @var bool */ protected $escapeOutput = false; diff --git a/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/MenuViewHelperTrait.php b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/MenuViewHelperTrait.php index c3ee21eee737e2ba68c2d480cb6d135cb6cbe6b0..30d35f739a902df05db2007e525f79f161c5f272 100644 --- a/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/MenuViewHelperTrait.php +++ b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/MenuViewHelperTrait.php @@ -14,12 +14,14 @@ namespace TYPO3\CMS\FluidStyledContent\ViewHelpers\Menu; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; use TYPO3\CMS\Frontend\Page\PageRepository; /** * Trait for Menu-ViewHelpers that require support functions for * working with menus that require page selection constraints. + * @deprecated since TYPO3 v8, will be removed in TYPO3 v9 */ trait MenuViewHelperTrait { @@ -37,10 +39,12 @@ trait MenuViewHelperTrait * * @param bool $includeNotInMenu Should pages which are hidden for menu's be included * @param bool $includeMenuSeparator Should pages of type "Menu separator" be included + * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, use AbstractMenuViewHelper instead of MenuViewHelperTrait * @return string */ protected function getPageConstraints($includeNotInMenu = false, $includeMenuSeparator = false) { + GeneralUtility::logDeprecatedFunction(); $constraints = array(); $constraints[] = 'doktype NOT IN (' . PageRepository::DOKTYPE_BE_USER_SECTION . ',' . PageRepository::DOKTYPE_RECYCLER . ',' . PageRepository::DOKTYPE_SYSFOLDER . ')'; @@ -62,10 +66,12 @@ trait MenuViewHelperTrait * * @param array $pageUids * @param int|NULL $entryLevel + * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, use AbstractMenuViewHelper instead of MenuViewHelperTrait * @return array */ protected function getPageUids(array $pageUids, $entryLevel = 0) { + GeneralUtility::logDeprecatedFunction(); $typoScriptFrontendController = $this->getTypoScriptFrontendController(); // Remove empty entries from array @@ -88,10 +94,12 @@ trait MenuViewHelperTrait /** * @param array $variables + * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, use AbstractMenuViewHelper instead of MenuViewHelperTrait * @return mixed */ protected function renderChildrenWithVariables(array $variables) { + GeneralUtility::logDeprecatedFunction(); foreach ($variables as $name => $value) { $this->templateVariableContainer->add($name, $value); } @@ -106,10 +114,12 @@ trait MenuViewHelperTrait } /** + * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, use AbstractMenuViewHelper instead of MenuViewHelperTrait * @return TypoScriptFrontendController */ protected function getTypoScriptFrontendController() { + GeneralUtility::logDeprecatedFunction(); return $GLOBALS['TSFE']; } } diff --git a/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/SectionViewHelper.php b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/SectionViewHelper.php index 8a3aedfa56a7208f0ab267b0b80b4366be37ff5e..a024abcbebb34f0086c047a3cca8b17bfb962f16 100644 --- a/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/SectionViewHelper.php +++ b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/SectionViewHelper.php @@ -15,7 +15,6 @@ namespace TYPO3\CMS\FluidStyledContent\ViewHelpers\Menu; */ use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper; /** * A view helper which returns content elements with 'Show in Section Menus' enabled @@ -45,9 +44,8 @@ use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper; * Content element 3 in page with uid = 1 and "Show in section menu's" enabled * </output> */ -class SectionViewHelper extends AbstractViewHelper +class SectionViewHelper extends AbstractMenuViewHelper { - use MenuViewHelperTrait; /** * Output escaping is disabled as child content contains HTML by default diff --git a/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/UpdatedViewHelper.php b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/UpdatedViewHelper.php index 708272596e16eb4fb1a901c1a2c4fd656debedee..d5c2eedc1fe88a775e4e19c99e67ad7aa309e363 100644 --- a/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/UpdatedViewHelper.php +++ b/typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Menu/UpdatedViewHelper.php @@ -14,8 +14,6 @@ namespace TYPO3\CMS\FluidStyledContent\ViewHelpers\Menu; * The TYPO3 project - inspiring people to share! */ -use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper; - /** * A view helper which returns recently updated subpages (multiple levels) of the given pages * @@ -35,13 +33,11 @@ use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper; * Recently updated subpage 3 * </output> */ -class UpdatedViewHelper extends AbstractViewHelper +class UpdatedViewHelper extends AbstractMenuViewHelper { - use MenuViewHelperTrait; - /** * Output escaping is disabled as child content contains HTML by default - * + * * @var bool */ protected $escapeOutput = false;