Bug #31951 » form_using_different_layouts.diff

Cornel Boppart, 2014-05-28 08:08

View differences:

typo3/sysext/form/Classes/Controller/FormController.php
55 55
	protected $requestHandler;
56 56

  
57 57
	/**
58
	 * @var \TYPO3\CMS\Form\Layout
59
	 */
60
	protected $layoutHandler;
61

  
62
	/**
58 63
	 * @var \TYPO3\CMS\Form\Utility\ValidatorUtility
59 64
	 */
60 65
	protected $validate;
......
69 74
		$this->typoscriptFactory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Domain\\Factory\\TypoScriptFactory');
70 75
		$this->localizationHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Localization');
71 76
		$this->requestHandler = $this->typoscriptFactory->setRequestHandler($typoscript);
77
		$this->layoutHandler = $this->typoscriptFactory->setLayoutHandler($this->typoscript);
72 78
		$this->validate = $this->typoscriptFactory->setRules($typoscript);
73 79
		$this->typoscript = $typoscript;
74 80
	}
......
167 173
	 * @return string The form HTML
168 174
	 */
169 175
	protected function renderForm() {
176
		$layout = $this->typoscriptFactory->getLayoutFromTypoScript($this->typoscript['form.']);
177

  
178
		$this->layoutHandler->setLayout($layout);
170 179
		$this->requestHandler->destroySession();
180

  
171 181
		$form = $this->typoscriptFactory->buildModelFromTyposcript($this->typoscript);
172 182
		/** @var $view \TYPO3\CMS\Form\View\Form\FormView */
173 183
		$view = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\View\\Form\\FormView', $form);
......
200 210
	 * @return string The confirmation screen HTML
201 211
	 */
202 212
	protected function renderConfirmation() {
213
		$layout = $this->typoscriptFactory->getLayoutFromTypoScript($this->typoscript['confirmation.']);
203 214
		$form = $this->typoscriptFactory->buildModelFromTyposcript($this->typoscript);
215

  
216
		$this->layoutHandler->setLayout($layout);
204 217
		$this->requestHandler->storeSession();
218

  
205 219
		$confirmationTyposcript = array();
206 220
		if (isset($this->typoscript['confirmation.'])) {
207 221
			$confirmationTyposcript = $this->typoscript['confirmation.'];
......
225 239
			$postProcessorTypoScript = $this->typoscript['postProcessor.'];
226 240
		}
227 241
		/** @var $postProcessor \TYPO3\CMS\Form\PostProcess\PostProcessor */
228
		$postProcessor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\PostProcess\\PostProcessor', $form, $postProcessorTypoScript);
242
		$postProcessor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\PostProcess\\PostProcessor', $form, $this->typoscriptFactory, $postProcessorTypoScript);
229 243
		$content = $postProcessor->process();
230 244
		$this->requestHandler->destroySession();
231 245
		return $content;
typo3/sysext/form/Classes/Domain/Factory/TypoScriptFactory.php
310 310
	public function setLayoutHandler(array $typoscript) {
311 311
		/** @var $layoutHandler \TYPO3\CMS\Form\Layout */
312 312
		$layoutHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Layout');
313
		// singleton
314
		if (isset($typoscript['layout.'])) {
315
			$layoutHandler->setLayout($typoscript['layout.']);
316
		}
313
		$layoutHandler->setLayout($this->getLayoutFromTypoScript($typoscript));
317 314
		return $layoutHandler;
318 315
	}
316
	
317
	/**
318
	 * Gets the layout that is configured in typoscript
319
	 * If no layout is defined, it returns an empty array to use the default.
320
	 *
321
	 * @param array $typoscript The typoscript configuration
322
	 * @return array The layout but with respecting its typoscript configuration
323
	 */
324
	public function getLayoutFromTypoScript($typoscript) {
325
		$layout = $typoscript['layout.'];
326
		return (!empty($layout)) ? $layout : array();
327
	}
319 328

  
320 329
	/**
321 330
	 * Set the request handler
typo3/sysext/form/Classes/PostProcess/PostProcessor.php
35 35
	 * Constructor
36 36
	 *
37 37
	 * @param \TYPO3\CMS\Form\Domain\Model\Form $form Form domain model
38
	 * @param array $typoScript Post processor TypoScript settings
38
	 * @param \TYPO3\CMS\Form\Domain\Factory\TypoScriptFactory $typoscriptFactory
39
	 * @param array	$typoScript Post processor TypoScript settings
39 40
	 */
40
	public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {
41
	public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, \TYPO3\CMS\Form\Domain\Factory\TypoScriptFactory $typoscriptFactory, array $typoScript) {
41 42
		$this->form = $form;
43
		$this->typoscriptFactory = $typoscriptFactory;
42 44
		$this->typoScript = $typoScript;
43 45
	}
44 46

  
......
54 56
		$html = '';
55 57
		if (is_array($this->typoScript)) {
56 58
			$keys = $this->sortTypoScriptKeyList();
59
			$layoutHandler = $this->typoscriptFactory->setLayoutHandler($this->typoScript);
60

  
57 61
			foreach ($keys as $key) {
58 62
				if (!(int)$key || strpos($key, '.') !== FALSE) {
59 63
					continue;
60 64
				}
61 65
				$className = FALSE;
66
				$processorName = $this->typoScript[$key];
62 67
				$processorArguments = array();
63 68
				if (isset($this->typoScript[$key . '.'])) {
64 69
					$processorArguments = $this->typoScript[$key . '.'];
65 70
				}
66
				if (class_exists($this->typoScript[$key], TRUE)) {
67
					$className = $this->typoScript[$key];
71
				if (class_exists($processorName, TRUE)) {
72
					$className = $processorName;
68 73
				} else {
69
					$classNameExpanded = 'TYPO3\\CMS\\Form\\PostProcess\\' . ucfirst(strtolower($this->typoScript[$key])) . 'PostProcessor';
74
					$classNameExpanded = 'TYPO3\\CMS\\Form\\PostProcess\\' . ucfirst(strtolower($processorName)) . 'PostProcessor';
70 75
					if (class_exists($classNameExpanded, TRUE)) {
71 76
						$className = $classNameExpanded;
72 77
					}
73 78
				}
74 79
				if ($className !== FALSE) {
80
					$layout = $this->typoscriptFactory->getLayoutFromTypoScript($this->typoScript[$processorName . '.']);
81
					$layoutHandler->setLayout($layout);
82

  
75 83
					$processor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className, $this->form, $processorArguments);
76 84
					if ($processor instanceof \TYPO3\CMS\Form\PostProcess\PostProcessorInterface) {
77 85
						$html .= $processor->process();
(4-4/4)