605d21bdcba2f5fcc703d5b9f2e763d84d41179a
[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 script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * *
12 * This script is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15 * General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with the script. *
19 * If not, see http://www.gnu.org/licenses/lgpl.html *
20 * *
21 * The TYPO3 project - inspiring people to share! *
22 * */
23 /**
24 * This is the bootstrap for Ajax Widget responses
25 */
26 class Bootstrap {
27
28 /**
29 * Back reference to the parent content object
30 * This has to be public as it is set directly from TYPO3
31 *
32 * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
33 */
34 public $cObj;
35
36 /**
37 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
38 */
39 protected $objectManager;
40
41 /**
42 * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
43 */
44 protected $configurationManager;
45
46 /**
47 * @param string $content The content
48 * @param array $configuration The TS configuration array
49 * @return string $content The processed content
50 */
51 public function run($content, $configuration) {
52 $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
53 $this->initializeConfiguration($configuration);
54 $this->configureObjectManager();
55 $ajaxWidgetContextHolder = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Widget\\AjaxWidgetContextHolder');
56 $widgetIdentifier = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('fluid-widget-id');
57 $widgetContext = $ajaxWidgetContextHolder->get($widgetIdentifier);
58 $configuration['extensionName'] = $widgetContext->getParentExtensionName();
59 $configuration['pluginName'] = $widgetContext->getParentPluginName();
60 $extbaseBootstrap = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Core\\Bootstrap');
61 $extbaseBootstrap->cObj = $this->cObj;
62 return $extbaseBootstrap->run($content, $configuration);
63 }
64
65 /**
66 * Initializes the Object framework.
67 *
68 * @param array $configuration
69 * @return void
70 * @see initialize()
71 */
72 public function initializeConfiguration($configuration) {
73 $this->configurationManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
74 /** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject */
75 $contentObject = isset($this->cObj) ? $this->cObj : \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
76 $this->configurationManager->setContentObject($contentObject);
77 $this->configurationManager->setConfiguration($configuration);
78 }
79
80 /**
81 * Configures the object manager object configuration from
82 * config.tx_extbase.objects
83 *
84 * @return void
85 * @see initialize()
86 * @todo this is duplicated code (see Tx_Extbase_Core_Bootstrap::configureObjectManager())
87 */
88 public function configureObjectManager() {
89 $typoScriptSetup = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
90 if (!is_array($typoScriptSetup['config.']['tx_extbase.']['objects.'])) {
91 return;
92 }
93 $objectContainer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class);
94 foreach ($typoScriptSetup['config.']['tx_extbase.']['objects.'] as $classNameWithDot => $classConfiguration) {
95 if (isset($classConfiguration['className'])) {
96 $originalClassName = rtrim($classNameWithDot, '.');
97 $objectContainer->registerImplementation($originalClassName, $classConfiguration['className']);
98 }
99 }
100 }
101 }