[BUGFIX] EXT:form - check for compatibility6 if old mailform is used
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / Hooks / ContentObjectHook.php
1 <?php
2 namespace TYPO3\CMS\Form\Hooks;
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\Utility\GeneralUtility;
18 use TYPO3\CMS\Core\Utility\ArrayUtility;
19 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
20 use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
21 use TYPO3\CMS\Form\Domain\Model\Configuration;
22 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
23
24 /**
25 * Hook cObjGetSingleExt
26 */
27 class ContentObjectHook {
28
29 /**
30 * Renders the application defined cObject FORM
31 * which overrides the TYPO3 default cObject FORM
32 *
33 * Convert FORM to COA_INT - COA_INT.10 = FORM_INT
34 * If FORM_INT is also dedected by the ContentObjectRenderer, and now
35 * the Extbaseplugin "Form" is initalized. At this time the
36 * controller "Frontend" action "execute" do the rest.
37 *
38 * @param string $typoScriptObjectName Name of the object
39 * @param array $typoScript TS configuration for this cObject
40 * @param string $typoScriptKey A string label used for the internal debugging tracking.
41 * @param ContentObjectRenderer $contentObject reference
42 * @return string HTML output
43 */
44 public function cObjGetSingleExt($typoScriptObjectName, array $typoScript, $typoScriptKey, ContentObjectRenderer $contentObject) {
45 $content = '';
46 if (
47 $typoScriptObjectName === 'FORM'
48 && !empty($typoScript['useDefaultContentObject'])
49 && ExtensionManagementUtility::isLoaded('compatibility6')
50 ) {
51 $content = $contentObject->getContentObject($typoScriptObjectName)->render($typoScript);
52 } elseif ($typoScriptObjectName === 'FORM') {
53 $mergedTypoScript = NULL;
54 if ($contentObject->data['CType'] === 'mailform') {
55 $bodytext = $contentObject->data['bodytext'];
56 /** @var $typoScriptParser TypoScriptParser */
57 $typoScriptParser = GeneralUtility::makeInstance(TypoScriptParser::class);
58 $typoScriptParser->parse($bodytext);
59 $mergedTypoScript = (array)$typoScriptParser->setup;
60 ArrayUtility::mergeRecursiveWithOverrule($mergedTypoScript, $typoScript);
61 // Disables content elements since TypoScript is handled that could contain insecure settings:
62 $mergedTypoScript[Configuration::DISABLE_CONTENT_ELEMENT_RENDERING] = TRUE;
63 }
64 $newTypoScript = array(
65 '10' => 'FORM_INT',
66 '10.' => (is_array($mergedTypoScript) ? $mergedTypoScript : $typoScript),
67 );
68 $content = $contentObject->cObjGetSingle('COA_INT', $newTypoScript);
69 // Only apply stdWrap to TypoScript that was NOT created by the wizard:
70 if (isset($typoScript['stdWrap.'])) {
71 $content = $contentObject->stdWrap($content, $typoScript['stdWrap.']);
72 }
73 } elseif ($typoScriptObjectName === 'FORM_INT') {
74 $extbase = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Core\Bootstrap::class);
75 $content = $extbase->run('', array(
76 'pluginName' => 'Form',
77 'extensionName' => 'Form',
78 'vendorName' => 'TYPO3\\CMS',
79 'controller' => 'Frontend',
80 'action' => 'show',
81 'settings' => array('typoscript' => $typoScript),
82 'persistence' => array(),
83 'view' => array(),
84 ));
85 }
86 return $content;
87 }
88 }