[FEATURE] Add fluid debug information to admin panel
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / Core / ViewHelper / ViewHelperResolver.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Core\ViewHelper;
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\Authentication\BackendUserAuthentication;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Extbase\Object\ObjectManager;
20 use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
21
22 /**
23 * Class ViewHelperResolver
24 *
25 * Class whose purpose is dedicated to resolving classes which
26 * can be used as ViewHelpers and ExpressionNodes in Fluid.
27 *
28 * This CMS-specific version of the ViewHelperResolver works
29 * almost exactly like the one from Fluid itself, with the main
30 * differences being that this one supports a legacy mode flag
31 * which when toggled on makes the Fluid parser behave exactly
32 * like it did in the legacy CMS Fluid package.
33 *
34 * In addition to modifying the behavior or the parser when
35 * legacy mode is requested, this ViewHelperResolver is also
36 * made capable of "mixing" two different ViewHelper namespaces
37 * to effectively create aliases for the Fluid core ViewHelpers
38 * to be loaded in the TYPO3\CMS\ViewHelpers scope as well.
39 */
40 class ViewHelperResolver extends \TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperResolver
41 {
42 /**
43 * Custom merged namespace for CMS Fluid adapter;
44 * will look for classes in both namespaces starting
45 * from the bottom.
46 *
47 * @var array
48 */
49 protected $namespaces = [
50 'f' => [
51 'TYPO3Fluid\\Fluid\\ViewHelpers',
52 'TYPO3\\CMS\\Fluid\\ViewHelpers'
53 ]
54 ];
55
56 /**
57 * ViewHelperResolver constructor
58 *
59 * Responsible for adding a third namespace in case this is requested from
60 * the admin panel - causes overlaying of `f:` with `f:debug`.
61 */
62 public function __construct()
63 {
64 $configuration = $this->getBackendUser()->uc['TSFE_adminConfig'];
65 if (TYPO3_MODE === 'FE'
66 && isset($configuration['preview_showFluidDebug'])
67 && $configuration['preview_showFluidDebug']
68 ) {
69 $this->namespaces['f'][] = 'TYPO3\\CMS\\Fluid\\ViewHelpers\\Debug';
70 }
71 }
72
73 /**
74 * @param string $viewHelperClassName
75 * @return \TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInterface
76 */
77 public function createViewHelperInstanceFromClassName($viewHelperClassName)
78 {
79 return $this->getObjectManager()->get($viewHelperClassName);
80 }
81
82 /**
83 * @return ObjectManagerInterface
84 */
85 protected function getObjectManager()
86 {
87 return GeneralUtility::makeInstance(ObjectManager::class);
88 }
89
90 /**
91 * @return BackendUserAuthentication
92 */
93 protected function getBackendUser()
94 {
95 return $GLOBALS['BE_USER'];
96 }
97 }