/**
  * Try to explode the element layout into 2 parts to get the
  * outer wrapping
  *
  * @param string $elementType
  * @param string $elementLayout
  * @return string
  * @deprecated since TYPO3 CMS 7, this function will be removed in TYPO3 CMS 8, as the functionality is now done via fluid
  */
 protected function determineElementOuterWraps($elementType, $elementLayout = '')
 {
     if ($this->formBuilder->getControllerAction() === 'show') {
         if ($elementType === 'TEXTAREA') {
             $return = $this->replaceTagWithMarker('textarea', 'body', $elementLayout);
         } elseif ($elementType === 'CONTENTELEMENT') {
             $return = $this->replaceTagWithMarker('content', 'body', $elementLayout);
         } elseif ($elementType === 'SELECT') {
             $return = $this->replaceTagWithMarker('select', 'body', $elementLayout);
         } elseif (in_array($elementType, $this->containerElements)) {
             $return = $this->replaceTagWithMarker('fieldset', 'body', $elementLayout);
         } else {
             $return = $this->replaceTagWithMarker('input', 'body', $elementLayout);
         }
     } else {
         if ($elementType === 'CONTENTELEMENT') {
             $return = $this->replaceTagWithMarker('content', 'body', $elementLayout);
         } elseif ($elementType === 'SELECT') {
             $return = $this->replaceTagWithMarker('elements', 'body', $elementLayout);
         } elseif (in_array($elementType, $this->containerElements)) {
             if ($this->formBuilder->getControllerAction() === 'confirmation') {
                 $return = $this->replaceTagWithMarker('fieldset', 'body', $elementLayout);
             } else {
                 $return = $this->replaceTagWithMarker('containerwrap', 'body', $elementLayout);
             }
         } else {
             $return = $this->replaceTagWithMarker('inputvalue', 'body', $elementLayout);
         }
     }
     return $return;
 }
 /**
  * If the id is not defined it is automatically generated
  * using the following syntax: field-{element_counter}
  * The id attribute will be transformed if it contains some
  * non allowed characters:
  * - spaces are changed into hyphens
  * - if the id start with a integer then transform it to field-{integer}
  * - remove all characters expect a-z A-Z 0-9 _ - : .
  *
  * @param string $id
  * @return string
  */
 protected function sanitizeIdAttribute($id)
 {
     $id = $this->formBuilder->getFormUtility()->sanitizeIdAttribute($id);
     if (empty($id)) {
         $id = 'field-' . $this->element->getElementCounter();
     }
     return $id;
 }
 /**
  * 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));
 }
 /**
  * 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);
             }
         }
     }
 }