/** * Compose the email data to be sent. * * @param FormConfig $formConfig * @param EmailConfig $emailConfig * @param FormData $formData */ private function emailCompose(FormConfig $formConfig, EmailConfig $emailConfig, $formData) { /* * Create message object */ $this->message = \Swift_Message::newInstance(); $this->message->setEncoder(\Swift_Encoding::get8BitEncoding()); // Set our Twig lookup path $this->addTwigPath(); // If the form has it's own templates defined, use those, else the globals. $templateSubject = $formConfig->getTemplates()->getSubject() ?: $this->config['templates']['subject']; $templateEmail = $formConfig->getTemplates()->getEmail() ?: $this->config['templates']['email']; $fieldmap = $this->config['fieldmap']['email']; /* * Subject */ $html = $this->app['render']->render($templateSubject, array($fieldmap['subject'] => $formConfig->getNotification()->getSubject(), $fieldmap['config'] => $emailConfig, $fieldmap['data'] => $formData)); $subject = new \Twig_Markup($html, 'UTF-8'); /* * Body */ $html = $this->app['render']->render($templateEmail, array($fieldmap['fields'] => $formConfig->getFields(), $fieldmap['config'] => $emailConfig, $fieldmap['data'] => $this->getBodyData($emailConfig, $formData))); $body = new \Twig_Markup($html, 'UTF-8'); /* * Build email */ $this->message->setSubject($subject)->setBody(strip_tags($body))->addPart($body, 'text/html'); }
/** * Process the fields to get usable data. * * @param FormConfig $formConfig * @param FormData $formData * * @throws FileUploadException */ protected function processFields(FormConfig $formConfig, FormData $formData) { foreach ($formData->keys() as $fieldName) { $field = $formData->get($fieldName); // Handle file uploads if ($field instanceof UploadedFile) { if (!$field->isValid()) { throw new FileUploadException($field->getErrorMessage()); } // Get the upload object $formData->set($fieldName, new FileUpload($this->app, $formConfig->getName(), $field)); if (!$this->config['uploads']['enabled']) { $this->app['logger.system']->debug('[BoltForms] File upload skipped as the administrator has disabled uploads for all forms.', ['event' => 'extensions']); continue; } // Take configured actions on the file $formData->get($fieldName)->move(); } // Handle events for custom data $fieldConf = $formConfig->getFields()->{$fieldName}(); if (isset($fieldConf['event']['name'])) { $formData->set($fieldName, $this->dispatchCustomDataEvent($fieldConf['event'])); } } }