/** * Load the property value to be used for validation. * * In case the object is a doctrine proxy, we need to load the real instance first. * * @param \TYPO3\CMS\Form\Domain\Model\ValidationElement $validationElement * @param string $propertyName * @return mixed */ protected function getPropertyValue(\TYPO3\CMS\Form\Domain\Model\ValidationElement $validationElement, $propertyName) { /** * If a confirmation page is set and a fileupload was done before * there is no incoming data if the process action is called. * The data is only in the session at this time. * This results in a negative validation (if a validation is set). * Therefore, look first in the session. */ if ($this->sessionUtility->getSessionData($propertyName)) { $propertyValue = $this->sessionUtility->getSessionData($propertyName); } else { $propertyValue = $validationElement->getIncomingField($propertyName); } return $propertyValue; }
/** * Loop through all elements of the session and attach the file * if its a uploaded file * * @return void */ protected function addAttachmentsFromSession() { $sessionData = $this->sessionUtility->getSessionData(); if (is_array($sessionData)) { foreach ($sessionData as $fieldName => $values) { if (is_array($values)) { foreach ($values as $file) { if (isset($file['tempFilename'])) { if (is_file($file['tempFilename']) && GeneralUtility::isAllowedAbsPath($file['tempFilename'])) { $this->mailMessage->attach(\Swift_Attachment::fromPath($file['tempFilename'])->setFilename($file['name'])); } } } } } } }
/** * Handles process action, actually processing the user * submitted data and forwarding it to post-processors * (e.g. sending out mail messages). * * @param \TYPO3\CMS\Form\Domain\Model\ValidationElement $model * @return void */ public function processAction(ValidationElement $model) { $this->skipForeignFormProcessing(); $this->controllerContext->setValidationElement($model); $form = $this->formBuilder->buildModel(); $postProcessorTypoScript = array(); if (isset($this->typoscript['postProcessor.'])) { $postProcessorTypoScript = $this->typoscript['postProcessor.']; } /** @var $postProcessor \TYPO3\CMS\Form\PostProcess\PostProcessor */ $postProcessor = $this->objectManager->get(\TYPO3\CMS\Form\PostProcess\PostProcessor::class, $form, $postProcessorTypoScript); $postProcessor->setControllerContext($this->controllerContext); // @todo What is happening here? $content = $postProcessor->process(); $this->sessionUtility->destroySession(); $this->forward('afterProcess', null, null, array('postProcessorContent' => $content)); }
/** * Set the htmlAttributes and the additionalAttributes * Remap htmlAttributes to additionalAttributes if needed * * @param ElementBuilder $elementBuilder * @param Element $element * @return void */ protected function setAttributes(ElementBuilder $elementBuilder, Element $element) { $htmlAttributes = $this->typoScriptRepository->getModelDefinedHtmlAttributes($element->getElementType()); $elementBuilder->setHtmlAttributes($htmlAttributes); $elementBuilder->setHtmlAttributeWildcards(); $elementBuilder->overlayUserdefinedHtmlAttributeValues(); $elementBuilder->setNameAndId(); $elementBuilder->overlayFixedHtmlAttributeValues(); // remove all NULL values $htmlAttributes = array_filter($elementBuilder->getHtmlAttributes()); $elementBuilder->setHtmlAttributes($htmlAttributes); $elementBuilder->moveHtmlAttributesToAdditionalArguments(); $elementBuilder->setViewHelperDefaulArgumentsToAdditionalArguments(); $elementBuilder->moveAllOtherUserdefinedPropertiesToAdditionalArguments(); $htmlAttributes = $elementBuilder->getHtmlAttributes(); $userConfiguredElementTypoScript = $elementBuilder->getUserConfiguredElementTypoScript(); $additionalArguments = $elementBuilder->getAdditionalArguments(); $element->setHtmlAttributes($htmlAttributes); $additionalArguments = $this->typoScriptService->convertTypoScriptArrayToPlainArray($additionalArguments); $additionalArguments['prefix'] = $this->configuration->getPrefix(); $element->setAdditionalArguments($additionalArguments); $this->handleIncomingValues($element, $userConfiguredElementTypoScript); if ($element->getElementType() === 'FORM' && $this->getControllerAction() === 'show') { if (empty($element->getHtmlAttribute('action'))) { if ($element->getAdditionalArgument('confirmation') && (int) $element->getAdditionalArgument('confirmation') === 1) { $element->setAdditionalArgument('action', 'confirmation'); } else { $element->setAdditionalArgument('action', 'process'); } } else { $element->setAdditionalArgument('pageUid', $element->getHtmlAttribute('action')); $element->setAdditionalArgument('action', null); } } // needed if confirmation page is enabled if ($this->sessionUtility->getSessionData($element->getName()) && $element->getAdditionalArgument('uploadedFiles') === null) { $element->setAdditionalArgument('uploadedFiles', $this->sessionUtility->getSessionData($element->getName())); } }
/** * Handle the incoming form data * * @param Element $element The element * @param ValidationElement $validationElement * @param mixed $modelValue * @param FormBuilder $formBuilder * @return void */ public function handleIncomingFormValues(Element $element, ValidationElement $validationElement, $modelValue, FormBuilder $formBuilder) { $elementName = $element->getName(); if ($element->getElementType() === 'CHECKBOX') { $groupedElement = false; if ($element->getParentElement()->getElementType() === 'CHECKBOXGROUP') { $incomingName = $element->getParentElement()->getName(); $groupedElement = true; } else { $incomingName = $elementName; } $incomingData = $formBuilder->getIncomingData()->getIncomingField($incomingName); $checked = false; if (is_array($incomingData)) { if (isset($incomingData[$elementName]) && $incomingData[$elementName] !== '') { $this->setAttribute($element, 'checked', 'checked'); $checked = true; } else { $this->setAttribute($element, 'checked', null); } } else { if (!empty($modelValue) && $incomingData === $modelValue || $incomingData === $incomingName . '-' . $element->getElementCounter()) { $this->setAttribute($element, 'checked', 'checked'); $checked = true; } else { $this->setAttribute($element, 'checked', null); } } if ($groupedElement && $checked) { $element->getParentElement()->setAdditionalArgument('atLeastOneCheckedChildElement', true); } } elseif ($element->getElementType() === 'RADIO') { $groupedElement = false; if ($element->getParentElement()->getElementType() === 'RADIOGROUP') { $incomingName = $element->getParentElement()->getName(); $groupedElement = true; } else { $incomingName = $elementName; } $checked = false; $incomingData = $formBuilder->getIncomingData()->getIncomingField($incomingName); if (!empty($modelValue) && $incomingData === $modelValue || $incomingData === $incomingName . '-' . $element->getElementCounter()) { $this->setAttribute($element, 'checked', 'checked'); $checked = true; } else { $this->setAttribute($element, 'checked', null); } if ($groupedElement && $checked) { $element->getParentElement()->setAdditionalArgument('atLeastOneCheckedChildElement', true); } } elseif ($element->getElementType() === 'OPTION') { $modelValue = (string) ($element->getAdditionalArgument('value') ?: $element->getElementCounter()); if ($element->getParentElement()->getElementType() === 'OPTGROUP') { $parentName = $element->getParentElement()->getParentElement()->getName(); } else { $parentName = $element->getParentElement()->getName(); } $incomingData = $formBuilder->getIncomingData()->getIncomingField($parentName); /* Multiselect */ if (is_array($incomingData)) { if (in_array($modelValue, $incomingData, true)) { $element->setHtmlAttribute('selected', 'selected'); } else { $element->setHtmlAttribute('selected', null); } } else { if ($modelValue === $incomingData) { $element->setHtmlAttribute('selected', 'selected'); } else { $element->setHtmlAttribute('selected', null); } } } elseif ($element->getElementType() === 'TEXTAREA') { $incomingData = $formBuilder->getIncomingData()->getIncomingField($elementName); $element->setAdditionalArgument('text', $incomingData); } elseif ($element->getElementType() === 'FILEUPLOAD') { if ($formBuilder->getValidationErrors() == null || $formBuilder->getValidationErrors() && $formBuilder->getValidationErrors()->forProperty($elementName)->hasErrors() !== true) { $uploadedFiles = $formBuilder->getIncomingData()->getIncomingField($elementName); if (is_array($uploadedFiles)) { foreach ($uploadedFiles as $key => &$file) { $tempFilename = $this->saveUploadedFile($file['tmp_name']); if (!$tempFilename) { unset($uploadedFiles[$key]); continue; } $file['tempFilename'] = $tempFilename; } $element->setAdditionalArgument('uploadedFiles', $uploadedFiles); $this->setAttribute($element, 'value', ''); $this->sessionUtility->setSessionData($elementName, $uploadedFiles); } } } }
/** * Skip the processing of foreign forms. * If there is more than one form on a page * we have to be sure that only the submitted form will be * processed. On data submission, the extbase action "confirmation" or * "process" is called. The detection which form is submitted * is done by the form prefix. All forms which do not have any * submitted data are skipped and forwarded to the show action. * * @return void */ protected function skipForeignFormProcessing() { if (!$this->request->hasArgument($this->configuration->getPrefix()) && !$this->sessionUtility->getSessionData()) { $this->forward('show'); } }