/** * Return array element by key. * * @param array $arguments * @param \Closure $renderChildrenClosure * @param RenderingContextInterface $renderingContext * @return string * @api */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { $element = $arguments['element']; $formRuntime = $arguments['formRuntime']; $property = null; if (!empty($arguments['property'])) { $property = $arguments['property']; } elseif (!empty($arguments['renderingOptionProperty'])) { $property = $arguments['renderingOptionProperty']; } if ($formRuntime === null) { /** @var RendererInterface $fluidFormRenderer */ $fluidFormRenderer = $renderingContext->getViewHelperVariableContainer()->getView(); $formRuntime = $fluidFormRenderer->getFormRuntime(); } return TranslationService::getInstance()->translateFormElementValue($element, $property, $formRuntime); }
/** * Read the option called $optionName from $this->options, and parse {...} * as object accessors. * * Then translate the value. * * If $optionName was not found, the corresponding default option is returned (from $this->defaultOptions) * * @param string $optionName * @return string|array|null * @api */ protected function parseOption(string $optionName) { if ($optionName === 'translation') { return null; } $optionValue = ArrayUtility::getValueByPath($this->options, $optionName); $defaultValue = ArrayUtility::getValueByPath($this->defaultOptions, $optionName); if ($optionValue === null && $defaultValue !== null) { $optionValue = $defaultValue; } if ($optionValue === null) { return null; } if (is_array($optionValue)) { return $optionValue; } $formRuntime = $this->finisherContext->getFormRuntime(); $optionToCompare = $optionValue; // You can encapsulate a option value with {}. // This enables you to access every getable property from the // TYPO3\CMS\Form\Domain\Runtime. // // For example: {formState.formValues.<elemenIdentifier>} // This is equal to "$formRuntime->getFormState()->getFormValues()[<elemenIdentifier>]" $optionValue = preg_replace_callback('/{([^}]+)}/', function ($match) use($formRuntime) { return ObjectAccess::getPropertyPath($formRuntime, $match[1]); }, $optionValue); if ($optionToCompare === $optionValue) { // This is just a shortcut for a {formState.formValues.<elementIdentifier>} notation. // If one of the finisher option values is equal // to a identifier from the form definition then // the value of the submitted form element is used // insteed. // Lets say you have a textfield in your form with the // identifier "Text1". If you put "Text1" // in the email finisher option "subject" then the submited value // from the "Text1" element is used as the email subject. $formValues = $this->finisherContext->getFormValues(); if (!is_bool($optionValue) && array_key_exists($optionValue, $formValues)) { $optionValue = $formRuntime[$optionValue]; } } if (isset($this->options['translation']['translationFile'])) { $optionValue = TranslationService::getInstance()->translateFinisherOption($formRuntime, $this->finisherIdentifier, $optionName, $optionValue, $this->options['translation']); } if (empty($optionValue)) { if ($defaultValue !== null) { $optionValue = $defaultValue; } } return $optionValue; }
/** * Returns the json encoded data which is used by the form editor * JavaScript app. * * @return string */ protected function getFormManagerAppInitialData() : string { $formManagerAppInitialData = ['selectablePrototypesConfiguration' => $this->formSettings['formManager']['selectablePrototypesConfiguration'], 'accessibleFormStorageFolders' => $this->getAccessibleFormStorageFolders(), 'endpoints' => ['create' => $this->controllerContext->getUriBuilder()->uriFor('create'), 'duplicate' => $this->controllerContext->getUriBuilder()->uriFor('duplicate'), 'delete' => $this->controllerContext->getUriBuilder()->uriFor('delete'), 'references' => $this->controllerContext->getUriBuilder()->uriFor('references')]]; $formManagerAppInitialData = ArrayUtility::reIndexNumericArrayKeysRecursive($formManagerAppInitialData); $formManagerAppInitialData = TranslationService::getInstance()->translateValuesRecursive($formManagerAppInitialData, $this->formSettings['formManager']['translationFile']); return json_encode($formManagerAppInitialData); }
/** * Reduce the Yaml settings by the 'formEditor' keyword. * * @return array */ protected function getFormEditorDefinitions() : array { $formEditorDefinitions = []; foreach ([$this->prototypeConfiguration, $this->prototypeConfiguration['formEditor']] as $configuration) { foreach ($configuration as $firstLevelItemKey => $firstLevelItemValue) { if (substr($firstLevelItemKey, -10) !== 'Definition') { continue; } $reducedKey = substr($firstLevelItemKey, 0, -10); foreach ($configuration[$firstLevelItemKey] as $formEditorDefinitionKey => $formEditorDefinitionValue) { if (isset($formEditorDefinitionValue['formEditor'])) { $formEditorDefinitionValue = array_intersect_key($formEditorDefinitionValue, array_flip(['formEditor'])); $formEditorDefinitions[$reducedKey][$formEditorDefinitionKey] = $formEditorDefinitionValue['formEditor']; } else { $formEditorDefinitions[$reducedKey][$formEditorDefinitionKey] = $formEditorDefinitionValue; } } } } $formEditorDefinitions = ArrayUtility::reIndexNumericArrayKeysRecursive($formEditorDefinitions); $formEditorDefinitions = TranslationService::getInstance()->translateValuesRecursive($formEditorDefinitions, $this->prototypeConfiguration['formEditor']['translationFile']); return $formEditorDefinitions; }
/** * Executes this finisher * @see AbstractFinisher::execute() * * @return void * @throws FinisherException */ protected function executeInternal() { $formRuntime = $this->finisherContext->getFormRuntime(); $standaloneView = $this->initializeStandaloneView(); $standaloneView->assign('form', $formRuntime); $translationService = TranslationService::getInstance(); if (isset($this->options['translation']['language']) && !empty($this->options['translation']['language'])) { $languageBackup = $translationService->getLanguage(); $translationService->setLanguage($this->options['translation']['language']); } $message = $standaloneView->render(); if (!empty($languageBackup)) { $translationService->setLanguage($languageBackup); } $subject = $this->parseOption('subject'); $recipientAddress = $this->parseOption('recipientAddress'); $recipientName = $this->parseOption('recipientName'); $senderAddress = $this->parseOption('senderAddress'); $senderName = $this->parseOption('senderName'); $replyToAddress = $this->parseOption('replyToAddress'); $carbonCopyAddress = $this->parseOption('carbonCopyAddress'); $blindCarbonCopyAddress = $this->parseOption('blindCarbonCopyAddress'); $format = $this->parseOption('format'); $attachUploads = $this->parseOption('attachUploads'); if (empty($subject)) { throw new FinisherException('The option "subject" must be set for the EmailFinisher.', 1327060320); } if (empty($recipientAddress)) { throw new FinisherException('The option "recipientAddress" must be set for the EmailFinisher.', 1327060200); } if (empty($senderAddress)) { throw new FinisherException('The option "senderAddress" must be set for the EmailFinisher.', 1327060210); } $mail = $this->objectManager->get(MailMessage::class); $mail->setFrom([$senderAddress => $senderName])->setTo([$recipientAddress => $recipientName])->setSubject($subject); if (!empty($replyToAddress)) { $mail->setReplyTo($replyToAddress); } if (!empty($carbonCopyAddress)) { $mail->setCc($carbonCopyAddress); } if (!empty($blindCarbonCopyAddress)) { $mail->setBcc($blindCarbonCopyAddress); } if ($format === self::FORMAT_PLAINTEXT) { $mail->setBody($message, 'text/plain'); } else { $mail->setBody($message, 'text/html'); } $elements = $formRuntime->getFormDefinition()->getRenderablesRecursively(); if ($attachUploads) { foreach ($elements as $element) { if (!$element instanceof FileUpload) { continue; } $file = $formRuntime[$element->getIdentifier()]; if ($file) { if ($file instanceof FileReference) { $file = $file->getOriginalResource(); } $mail->attach(\Swift_Attachment::newInstance($file->getContents(), $file->getName(), $file->getMimeType())); } } } $mail->send(); }