[TASK] Remove old language labels in EXT:setup
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / ContentObject / FormContentObject.php
1 <?php
2 namespace TYPO3\CMS\Form\ContentObject;
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\TypoScript\Parser\TypoScriptParser;
18 use TYPO3\CMS\Core\Utility\ArrayUtility;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Form\Domain\Model\Configuration;
21 use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject;
22 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
23
24 /**
25 * FORM cObject, a wrapper to allow to use 10 = FORM in TypoScript
26 * which actually executes the Extbase plugin (marked as non-cached)
27 */
28 class FormContentObject extends AbstractContentObject
29 {
30 /**
31 * Renders the application defined cObject FORM
32 *
33 * The Extbase plugin "Form" is initialized. At this time, the
34 * controller "Frontend" action "show" does the rest.
35 *
36 * @param array $conf TS configuration for this cObject
37 * @return string HTML output
38 * @throws \InvalidArgumentException
39 */
40 public function render($conf = [])
41 {
42 $mergedTypoScript = null;
43 // If the FORM configuration is retrieved from the database
44 // all TypoScript interpretation will be disabled for security.
45 if ($this->cObj->data['CType'] === 'mailform') {
46 // If the FORM configuration is retrieved from the database
47 // and a predefined form is selected then the TypoScript
48 // interpretation is allowed.
49 $renderPredefinedForm = false;
50 $predefinedFormIdentifier = null;
51 if (!empty($this->cObj->data['tx_form_predefinedform'])) {
52 $predefinedFormIdentifier = $this->cObj->data['tx_form_predefinedform'];
53 if (isset($this->getTypoScriptFrontendController()->tmpl->setup['plugin.']['tx_form.']['predefinedForms.'][$predefinedFormIdentifier . '.'])) {
54 $renderPredefinedForm = true;
55 } else {
56 throw new \InvalidArgumentException('No FORM configuration for identifier "' . $predefinedFormIdentifier . '" available.', 1466769483);
57 }
58 }
59
60 if ($renderPredefinedForm && $predefinedFormIdentifier) {
61 $mergedTypoScript = $this->getTypoScriptFrontendController()->tmpl->setup['plugin.']['tx_form.']['predefinedForms.'][$predefinedFormIdentifier . '.'];
62 ArrayUtility::mergeRecursiveWithOverrule($mergedTypoScript, $conf);
63 } else {
64 $bodytext = $this->cObj->data['bodytext'];
65 /** @var $typoScriptParser TypoScriptParser */
66 $typoScriptParser = GeneralUtility::makeInstance(TypoScriptParser::class);
67 $typoScriptParser->parse($bodytext);
68 $mergedTypoScript = (array)$typoScriptParser->setup;
69 ArrayUtility::mergeRecursiveWithOverrule($mergedTypoScript, $conf);
70 // Disables TypoScript interpretation since TypoScript is handled that could contain insecure settings:
71 $mergedTypoScript[Configuration::DISABLE_CONTENT_ELEMENT_RENDERING] = true;
72 }
73 }
74
75 // make sure the extbase plugin is marked as Uncached
76 $content = $this->prepareNonCacheableUserFunction(is_array($mergedTypoScript) ? $mergedTypoScript : $conf);
77
78 // Only apply stdWrap to TypoScript that was NOT created by the wizard:
79 if (isset($conf['stdWrap.'])) {
80 $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
81 }
82 return $content;
83 }
84
85 /**
86 * Set up the extbase plugin to be a non-cacheable user function
87 *
88 * @param array $typoScript
89 * @return string the content as placeholder for USER_INT code
90 */
91 protected function prepareNonCacheableUserFunction($typoScript)
92 {
93 $configuration = [
94 'userFunc' => 'TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run',
95 'pluginName' => 'Form',
96 'extensionName' => 'Form',
97 'vendorName' => 'TYPO3\\CMS',
98 'controller' => 'Frontend',
99 'action' => 'show',
100 'settings' => ['typoscript' => $typoScript],
101 'persistence' => [],
102 'view' => [],
103 ];
104
105 $this->cObj->setUserObjectType(ContentObjectRenderer::OBJECTTYPE_USER_INT);
106 $substKey = 'INT_SCRIPT.' . $this->getTypoScriptFrontendController()->uniqueHash();
107 $content = '<!--' . $substKey . '-->';
108 $this->getTypoScriptFrontendController()->config['INTincScript'][$substKey] = [
109 'conf' => $configuration,
110 'cObj' => serialize($this->cObj),
111 'type' => 'FUNC'
112 ];
113 $this->cObj->setUserObjectType(false);
114 return $content;
115 }
116
117 /**
118 * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
119 */
120 protected function getTypoScriptFrontendController()
121 {
122 return $GLOBALS['TSFE'];
123 }
124 }