/** * Updates the local properties - called after * new TypoScript has been assigned in this object. */ protected function update() { // Determine content rendering mode. If activated, cObject and stdWrap can be // used to execute various processes that must not be allowed on TypoScript // that has been created by non-privileged backend users (= insecure TypoScript) $this->setContentElementRendering(empty($this->typoScript[static::DISABLE_CONTENT_ELEMENT_RENDERING])); // Determine the HTML form element prefix to distinguish // different form components on the same page in the frontend if (!empty($this->typoScript['prefix'])) { $this->setPrefix($this->typoScript['prefix']); } // Determine compatibility behavior $this->setCompatibility((bool) $this->typoScriptRepository->getModelConfigurationByScope('FORM', 'compatibilityMode')); if (isset($this->typoScript['compatibilityMode'])) { if ((int) $this->typoScript['compatibilityMode'] === 0) { $this->setCompatibility(false); } else { $this->setCompatibility(true); } } // Set the theme name if (!empty($this->typoScript['themeName'])) { $this->setThemeName($this->typoScript['themeName']); } elseif (!empty($this->typoScriptRepository->getModelConfigurationByScope('FORM', 'themeName'))) { $this->setThemeName($this->typoScriptRepository->getModelConfigurationByScope('FORM', 'themeName')); } else { $this->setThemeName(static::DEFAULT_THEME_NAME); } }
/** * Set the name and id attribute * * @return array */ public function setNameAndId() { if ($this->element->getParentElement() && (int) $this->typoScriptRepository->getModelConfigurationByScope($this->element->getParentElement()->getElementType(), 'childrenInheritName') == 1) { $this->htmlAttributes['name'] = $this->element->getParentElement()->getName(); $this->additionalArguments['multiple'] = '1'; $name = $this->sanitizeNameAttribute($this->userConfiguredElementTyposcript['name']); $this->element->setName($name); } else { $this->htmlAttributes['name'] = $this->sanitizeNameAttribute($this->htmlAttributes['name']); $this->element->setName($this->htmlAttributes['name']); } $this->htmlAttributes['id'] = $this->sanitizeIdAttribute($this->htmlAttributes['id']); $this->element->setId($this->htmlAttributes['id']); }
/** * 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)); }
/** * 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.'); } } } } }