Example #1
0
 /**
  * The values of the submitted form (after validation and property mapping)
  *
  * @return array
  * @api
  */
 public function getFormValues() : array
 {
     return $this->formRuntime->getFormState()->getFormValues();
 }
Example #2
0
 /**
  * @param RootRenderableInterface $element
  * @param string $property
  * @param FormRuntime $formRuntime
  * @return string|array
  * @throws \InvalidArgumentException
  * @internal
  */
 public function translateFormElementValue(RootRenderableInterface $element, string $property, FormRuntime $formRuntime)
 {
     if (empty($property)) {
         throw new \InvalidArgumentException('The argument "property" is empty', 1476216007);
     }
     $propertyType = 'properties';
     $renderingOptions = $element->getRenderingOptions();
     if ($property === 'label') {
         $defaultValue = $element->getLabel();
     } else {
         if ($element instanceof FormElementInterface) {
             $defaultValue = ArrayUtility::getValueByPath($element->getProperties(), $property);
         } else {
             $propertyType = 'renderingOptions';
             $defaultValue = ArrayUtility::getValueByPath($renderingOptions, $property);
         }
     }
     if (isset($renderingOptions['translation']['translatePropertyValueIfEmpty'])) {
         $translatePropertyValueIfEmpty = $renderingOptions['translation']['translatePropertyValueIfEmpty'];
     } else {
         $translatePropertyValueIfEmpty = true;
     }
     if (empty($defaultValue) && !$translatePropertyValueIfEmpty) {
         return $defaultValue;
     }
     $defaultValue = empty($defaultValue) ? '' : $defaultValue;
     $translationFile = $renderingOptions['translation']['translationFile'];
     $language = null;
     if (isset($renderingOptions['translation']['language'])) {
         $language = $renderingOptions['translation']['language'];
     }
     $translationKeyChain = [];
     if ($property === 'options' && is_array($defaultValue)) {
         foreach ($defaultValue as $optionValue => &$optionLabel) {
             $translationKeyChain = [sprintf('%s:%s.element.%s.%s.%s.%s', $translationFile, $formRuntime->getIdentifier(), $element->getIdentifier(), $propertyType, $property, $optionValue), sprintf('%s:element.%s.%s.%s.%s', $translationFile, $element->getIdentifier(), $propertyType, $property, $optionValue)];
             $translatedValue = $this->processTranslationChain($translationKeyChain, $language);
             $optionLabel = empty($translatedValue) ? $optionLabel : $translatedValue;
         }
         $translatedValue = $defaultValue;
     } else {
         $translationKeyChain = [sprintf('%s:%s.element.%s.%s.%s', $translationFile, $formRuntime->getIdentifier(), $element->getIdentifier(), $propertyType, $property), sprintf('%s:element.%s.%s.%s', $translationFile, $element->getIdentifier(), $propertyType, $property), sprintf('%s:element.%s.%s.%s', $translationFile, $element->getType(), $propertyType, $property)];
         $translatedValue = $this->processTranslationChain($translationKeyChain, $language);
         $translatedValue = empty($translatedValue) ? $defaultValue : $translatedValue;
     }
     return $translatedValue;
 }