コード例 #1
0
ファイル: FormBuilder.php プロジェクト: graurus/testgit_t37
 /**
  * Handles the incoming form data
  *
  * @param Element $element
  * @param array $userConfiguredElementTypoScript
  * @return array
  */
 protected function handleIncomingValues(Element $element, array $userConfiguredElementTypoScript)
 {
     if (!$this->getIncomingData()) {
         return;
     }
     $elementName = $element->getName();
     if ($element->getHtmlAttribute('value') !== null) {
         $modelValue = $element->getHtmlAttribute('value');
     } else {
         $modelValue = $element->getAdditionalArgument('value');
     }
     if ($this->getIncomingData()->getIncomingField($elementName) !== null) {
         /* filter values and set it back to incoming fields */
         /* remove xss every time */
         $userConfiguredElementTypoScript['filters.'][-1] = 'removexss';
         $keys = TemplateService::sortedKeyList($userConfiguredElementTypoScript['filters.']);
         foreach ($keys as $key) {
             $class = $userConfiguredElementTypoScript['filters.'][$key];
             if ((int) $key && strpos($key, '.') === false) {
                 $filterArguments = $userConfiguredElementTypoScript['filters.'][$key . '.'];
                 $filterClassName = $this->typoScriptRepository->getRegisteredClassName((string) $class, 'registeredFilters');
                 if ($filterClassName !== null) {
                     // toDo: handel array values
                     if (is_string($this->getIncomingData()->getIncomingField($elementName))) {
                         if (is_null($filterArguments)) {
                             $filter = $this->objectManager->get($filterClassName);
                         } else {
                             $filter = $this->objectManager->get($filterClassName, $filterArguments);
                         }
                         if ($filter) {
                             $value = $filter->filter($this->getIncomingData()->getIncomingField($elementName));
                             $this->getIncomingData()->setIncomingField($elementName, $value);
                         } else {
                             throw new \RuntimeException('Class "' . $filterClassName . '" could not be loaded.');
                         }
                     }
                 } else {
                     throw new \RuntimeException('Class "' . $filterClassName . '" not registered via TypoScript.');
                 }
             }
         }
         if ($element->getHtmlAttribute('value') !== null) {
             $element->setHtmlAttribute('value', $this->getIncomingData()->getIncomingField($elementName));
         } else {
             $element->setAdditionalArgument('value', $this->getIncomingData()->getIncomingField($elementName));
         }
     }
     $this->signalSlotDispatcher->dispatch(__CLASS__, 'txFormHandleIncomingValues', array($element, $this->getIncomingData(), $modelValue, $this));
 }
コード例 #2
0
 /**
  * Build validation rules from typoscript.
  * The old breakOnError property are no longer supported
  *
  * @param array $rawArgument
  * @return void
  */
 public function buildRules(array $rawArgument = array())
 {
     $userConfiguredFormTyposcript = $this->configuration->getTypoScript();
     $rulesTyposcript = isset($userConfiguredFormTyposcript['rules.']) ? $userConfiguredFormTyposcript['rules.'] : null;
     $this->rules[$this->configuration->getPrefix()] = array();
     if (is_array($rulesTyposcript)) {
         $keys = TemplateService::sortedKeyList($rulesTyposcript);
         foreach ($keys as $key) {
             $ruleName = $rulesTyposcript[$key];
             $validatorClassName = $this->typoScriptRepository->getRegisteredClassName($ruleName, 'registeredValidators');
             if ($validatorClassName === null) {
                 throw new \RuntimeException('Class "' . $validatorClassName . '" not registered via typoscript.');
             }
             if ((int) $key && strpos($key, '.') === false) {
                 $ruleArguments = $rulesTyposcript[$key . '.'];
                 $fieldName = $this->formUtility->sanitizeNameAttribute($ruleArguments['element']);
                 // remove unsupported validator options
                 $validatorOptions = $ruleArguments;
                 $validatorOptions['errorMessage'] = array($ruleArguments['error.'], $ruleArguments['error']);
                 $keysToRemove = array_flip(array('breakOnError', 'message', 'message.', 'error', 'error.', 'showMessage'));
                 $validatorOptions = array_diff_key($validatorOptions, $keysToRemove);
                 // Instantiate the validator to check if all required options are assigned
                 // and to use the validator message rendering function to pre-render the mandatory message
                 /** @var AbstractValidator $validator */
                 $validator = $this->objectManager->get($validatorClassName, $validatorOptions);
                 if ($validator instanceof AbstractValidator) {
                     $validator->setRawArgument($rawArgument);
                     $validator->setFormUtility($this->formUtility);
                     if ((int) $ruleArguments['showMessage'] === 1) {
                         $mandatoryMessage = $validator->renderMessage($ruleArguments['message.'], $ruleArguments['message']);
                     } else {
                         $mandatoryMessage = NULL;
                     }
                     $this->rules[$this->configuration->getPrefix()][$fieldName][] = array('validator' => $validator, 'validatorName' => $validatorClassName, 'validatorOptions' => $validatorOptions, 'mandatoryMessage' => $mandatoryMessage);
                 } else {
                     throw new \RuntimeException('Class "' . $validatorClassName . '" could not be loaded.');
                 }
             }
         }
     }
 }