Project

General

Profile

Bug #31951 » form_using_different_layouts.diff

Cornel Boppart, 2014-05-28 08:08

View differences:

typo3/sysext/form/Classes/Controller/FormController.php
protected $requestHandler;
/**
* @var \TYPO3\CMS\Form\Layout
*/
protected $layoutHandler;
/**
* @var \TYPO3\CMS\Form\Utility\ValidatorUtility
*/
protected $validate;
......
$this->typoscriptFactory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Domain\\Factory\\TypoScriptFactory');
$this->localizationHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Localization');
$this->requestHandler = $this->typoscriptFactory->setRequestHandler($typoscript);
$this->layoutHandler = $this->typoscriptFactory->setLayoutHandler($this->typoscript);
$this->validate = $this->typoscriptFactory->setRules($typoscript);
$this->typoscript = $typoscript;
}
......
* @return string The form HTML
*/
protected function renderForm() {
$layout = $this->typoscriptFactory->getLayoutFromTypoScript($this->typoscript['form.']);
$this->layoutHandler->setLayout($layout);
$this->requestHandler->destroySession();
$form = $this->typoscriptFactory->buildModelFromTyposcript($this->typoscript);
/** @var $view \TYPO3\CMS\Form\View\Form\FormView */
$view = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\View\\Form\\FormView', $form);
......
* @return string The confirmation screen HTML
*/
protected function renderConfirmation() {
$layout = $this->typoscriptFactory->getLayoutFromTypoScript($this->typoscript['confirmation.']);
$form = $this->typoscriptFactory->buildModelFromTyposcript($this->typoscript);
$this->layoutHandler->setLayout($layout);
$this->requestHandler->storeSession();
$confirmationTyposcript = array();
if (isset($this->typoscript['confirmation.'])) {
$confirmationTyposcript = $this->typoscript['confirmation.'];
......
$postProcessorTypoScript = $this->typoscript['postProcessor.'];
}
/** @var $postProcessor \TYPO3\CMS\Form\PostProcess\PostProcessor */
$postProcessor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\PostProcess\\PostProcessor', $form, $postProcessorTypoScript);
$postProcessor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\PostProcess\\PostProcessor', $form, $this->typoscriptFactory, $postProcessorTypoScript);
$content = $postProcessor->process();
$this->requestHandler->destroySession();
return $content;
typo3/sysext/form/Classes/Domain/Factory/TypoScriptFactory.php
public function setLayoutHandler(array $typoscript) {
/** @var $layoutHandler \TYPO3\CMS\Form\Layout */
$layoutHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Layout');
// singleton
if (isset($typoscript['layout.'])) {
$layoutHandler->setLayout($typoscript['layout.']);
}
$layoutHandler->setLayout($this->getLayoutFromTypoScript($typoscript));
return $layoutHandler;
}
/**
* Gets the layout that is configured in typoscript
* If no layout is defined, it returns an empty array to use the default.
*
* @param array $typoscript The typoscript configuration
* @return array The layout but with respecting its typoscript configuration
*/
public function getLayoutFromTypoScript($typoscript) {
$layout = $typoscript['layout.'];
return (!empty($layout)) ? $layout : array();
}
/**
* Set the request handler
typo3/sysext/form/Classes/PostProcess/PostProcessor.php
* Constructor
*
* @param \TYPO3\CMS\Form\Domain\Model\Form $form Form domain model
* @param array $typoScript Post processor TypoScript settings
* @param \TYPO3\CMS\Form\Domain\Factory\TypoScriptFactory $typoscriptFactory
* @param array $typoScript Post processor TypoScript settings
*/
public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {
public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, \TYPO3\CMS\Form\Domain\Factory\TypoScriptFactory $typoscriptFactory, array $typoScript) {
$this->form = $form;
$this->typoscriptFactory = $typoscriptFactory;
$this->typoScript = $typoScript;
}
......
$html = '';
if (is_array($this->typoScript)) {
$keys = $this->sortTypoScriptKeyList();
$layoutHandler = $this->typoscriptFactory->setLayoutHandler($this->typoScript);
foreach ($keys as $key) {
if (!(int)$key || strpos($key, '.') !== FALSE) {
continue;
}
$className = FALSE;
$processorName = $this->typoScript[$key];
$processorArguments = array();
if (isset($this->typoScript[$key . '.'])) {
$processorArguments = $this->typoScript[$key . '.'];
}
if (class_exists($this->typoScript[$key], TRUE)) {
$className = $this->typoScript[$key];
if (class_exists($processorName, TRUE)) {
$className = $processorName;
} else {
$classNameExpanded = 'TYPO3\\CMS\\Form\\PostProcess\\' . ucfirst(strtolower($this->typoScript[$key])) . 'PostProcessor';
$classNameExpanded = 'TYPO3\\CMS\\Form\\PostProcess\\' . ucfirst(strtolower($processorName)) . 'PostProcessor';
if (class_exists($classNameExpanded, TRUE)) {
$className = $classNameExpanded;
}
}
if ($className !== FALSE) {
$layout = $this->typoscriptFactory->getLayoutFromTypoScript($this->typoScript[$processorName . '.']);
$layoutHandler->setLayout($layout);
$processor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className, $this->form, $processorArguments);
if ($processor instanceof \TYPO3\CMS\Form\PostProcess\PostProcessorInterface) {
$html .= $processor->process();
(4-4/4)