14d8c67536123adf6fcb4c990d54cb3a1506e15c
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / Core / Widget / Bootstrap.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Core\Widget;
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 /**
18 * This is the bootstrap for Ajax Widget responses
19 */
20 class Bootstrap
21 {
22 /**
23 * Back reference to the parent content object
24 * This has to be public as it is set directly from TYPO3
25 *
26 * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
27 */
28 public $cObj;
29
30 /**
31 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
32 */
33 protected $objectManager;
34
35 /**
36 * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
37 */
38 protected $configurationManager;
39
40 /**
41 * @param string $content The content
42 * @param array $configuration The TS configuration array
43 * @return string $content The processed content
44 */
45 public function run($content, $configuration)
46 {
47 $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
48 $this->initializeConfiguration($configuration);
49 $this->configureObjectManager();
50 $ajaxWidgetContextHolder = $this->objectManager->get(\TYPO3\CMS\Fluid\Core\Widget\AjaxWidgetContextHolder::class);
51 $widgetIdentifier = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('fluid-widget-id');
52 $widgetContext = $ajaxWidgetContextHolder->get($widgetIdentifier);
53 $configuration['extensionName'] = $widgetContext->getParentExtensionName();
54 $configuration['pluginName'] = $widgetContext->getParentPluginName();
55 $extbaseBootstrap = $this->objectManager->get(\TYPO3\CMS\Extbase\Core\Bootstrap::class);
56 $extbaseBootstrap->cObj = $this->cObj;
57 return $extbaseBootstrap->run($content, $configuration);
58 }
59
60 /**
61 * Initializes the Object framework.
62 *
63 * @param array $configuration
64 * @see initialize()
65 */
66 public function initializeConfiguration($configuration)
67 {
68 $this->configurationManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::class);
69 /** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject */
70 $contentObject = isset($this->cObj) ? $this->cObj : \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
71 $this->configurationManager->setContentObject($contentObject);
72 $this->configurationManager->setConfiguration($configuration);
73 }
74
75 /**
76 * Configures the object manager object configuration from
77 * config.tx_extbase.objects
78 *
79 * @see initialize()
80 * @todo this is duplicated code (see \TYPO3\CMS\Extbase\Core\Bootstrap::configureObjectManager())
81 */
82 public function configureObjectManager()
83 {
84 $typoScriptSetup = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
85 if (!is_array($typoScriptSetup['config.']['tx_extbase.']['objects.'])) {
86 return;
87 }
88 $objectContainer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class);
89 foreach ($typoScriptSetup['config.']['tx_extbase.']['objects.'] as $classNameWithDot => $classConfiguration) {
90 if (isset($classConfiguration['className'])) {
91 $originalClassName = rtrim($classNameWithDot, '.');
92 $objectContainer->registerImplementation($originalClassName, $classConfiguration['className']);
93 }
94 }
95 }
96 }