TYPO3 CMS  TYPO3_6-2
FormController.php
Go to the documentation of this file.
1 <?php
3 
24 
30  protected $typoscript = array();
31 
35  protected $typoscriptFactory;
36 
41 
45  protected $requestHandler;
46 
50  protected $layoutHandler;
51 
55  protected $validate;
56 
63  public function initialize(array $typoscript) {
64  $this->typoscriptFactory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Domain\\Factory\\TypoScriptFactory');
65  $this->localizationHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Localization');
66  $this->layoutHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Layout');
67  $this->requestHandler = $this->typoscriptFactory->setRequestHandler($typoscript);
68  $this->validate = $this->typoscriptFactory->setRules($typoscript);
69  $this->typoscript = $typoscript;
70  }
71 
89  public function cObjGetSingleExt($typoScriptObjectName, array $typoScript, $typoScriptKey, \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject) {
90  $content = '';
91  if ($typoScriptObjectName === 'FORM' && !empty($typoScript['useDefaultContentObject'])) {
92  $content = $contentObject->getContentObject($typoScriptObjectName)->render($typoScript);
93  } elseif ($typoScriptObjectName === 'FORM') {
94  if ($contentObject->data['CType'] === 'mailform') {
95  $bodytext = $contentObject->data['bodytext'];
97  $typoScriptParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\Parser\\TypoScriptParser');
98  $typoScriptParser->parse($bodytext);
99  $mergedTypoScript = (array)$typoScriptParser->setup;
100  \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($mergedTypoScript, (array)$typoScript);
101  // Disables content elements since TypoScript is handled that could contain insecure settings:
103  }
104  $newTypoScript = array(
105  '10' => 'FORM_INT',
106  '10.' => is_array($mergedTypoScript) ? $mergedTypoScript : $typoScript,
107  );
108  $content = $contentObject->COBJ_ARRAY($newTypoScript, 'INT');
109  // Only apply stdWrap to TypoScript that was NOT created by the wizard:
110  if (isset($typoScript['stdWrap.'])) {
111  $content = $contentObject->stdWrap($content, $typoScript['stdWrap.']);
112  }
113  } elseif ($typoScriptObjectName === 'FORM_INT') {
114  $this->initialize($typoScript);
115  $content = $this->execute();
116  }
117  return $content;
118  }
119 
125  public function execute() {
126  // Form
127  if ($this->showForm()) {
128  $content = $this->renderForm();
129  } elseif ($this->showConfirmation()) {
130  $content = $this->renderConfirmation();
131  } else {
132  $content = $this->doPostProcessing();
133  }
134  return $content;
135  }
136 
146  protected function showForm() {
147  $show = FALSE;
148  $submittedByPrefix = $this->requestHandler->getByMethod();
149  if (
150  $submittedByPrefix === NULL ||
151  !empty($submittedByPrefix) && !$this->validate->isValid() ||
152  !empty($submittedByPrefix) && $this->validate->isValid() &&
153  $this->requestHandler->getPost('confirmation-false', NULL) !== NULL
154  ) {
155  $show = TRUE;
156  }
157  return $show;
158  }
159 
165  protected function renderForm() {
166  $layout = $this->typoscriptFactory->getLayoutFromTypoScript($this->typoscript['form.']);
167  $this->layoutHandler->setLayout($layout);
168  $this->requestHandler->destroySession();
169 
170  $form = $this->typoscriptFactory->buildModelFromTyposcript($this->typoscript);
172  $view = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\View\\Form\\FormView', $form);
173  return $view->get();
174  }
175 
186  protected function showConfirmation() {
187  $show = FALSE;
188  if (isset($this->typoscript['confirmation']) && $this->typoscript['confirmation'] == 1 && $this->requestHandler->getPost('confirmation-true', NULL) === NULL) {
189  $show = TRUE;
190  }
191  return $show;
192  }
193 
201  protected function renderConfirmation() {
202  $confirmationTyposcript = array();
203  if (isset($this->typoscript['confirmation.'])) {
204  $confirmationTyposcript = $this->typoscript['confirmation.'];
205  }
206 
207  $layout = $this->typoscriptFactory->getLayoutFromTypoScript($confirmationTyposcript);
208  $form = $this->typoscriptFactory->buildModelFromTyposcript($this->typoscript);
209 
210  $this->layoutHandler->setLayout($layout);
211  $this->requestHandler->storeSession();
213  $view = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\View\\Confirmation\\ConfirmationView', $form, $confirmationTyposcript);
214  return $view->get();
215  }
216 
224  protected function doPostProcessing() {
225  $form = $this->typoscriptFactory->buildModelFromTyposcript($this->typoscript);
226  $postProcessorTypoScript = array();
227  if (isset($this->typoscript['postProcessor.'])) {
228  $postProcessorTypoScript = $this->typoscript['postProcessor.'];
229  }
231  $postProcessor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\PostProcess\\PostProcessor', $form, $postProcessorTypoScript);
232  $content = $postProcessor->process();
233  $this->requestHandler->destroySession();
234  return $content;
235  }
236 
237 }