/** * {@inheritdoc} */ public function process(Email $model) { $issue_contexts = array_filter($model->getContexts(), function ($context) { return $context instanceof Issue; }); /* @var $issue Issue */ $issue = array_pop($issue_contexts); if ($this->request->getMethod() === 'GET') { $tos = $model->getTo(); $tos[] = $issue->getReporter()->getEmail(); $model->setTo($tos); $model->setSubject(sprintf('%s %s', $issue->getCode(), $issue->getSummary())); } parent::process($model); }
/** * {@inheritdoc} */ protected function executeAction($context) { $type = 'txt'; $emailModel = new Email(); $emailModel->setFrom($this->getEmailAddress($context, $this->options['from'])); $to = []; foreach ($this->options['to'] as $email) { if ($email) { $to[] = $this->getEmailAddress($context, $email); } } $emailModel->setTo($to); $emailModel->setSubject($this->contextAccessor->getValue($context, $this->options['subject'])); $emailModel->setBody($this->contextAccessor->getValue($context, $this->options['body'])); if (array_key_exists('type', $this->options) && in_array($this->options['type'], ['txt', 'html'], true)) { $type = $this->options['type']; } $emailModel->setType($type); $emailUser = $this->emailProcessor->process($emailModel); if (array_key_exists('attribute', $this->options)) { $this->contextAccessor->setValue($context, $this->options['attribute'], $emailUser->getEmail()); } }
/** * @param EmailModel $model */ protected function applySubject(EmailModel $model) { if ($this->request->query->has('subject')) { $subject = trim($this->request->query->get('subject')); $model->setSubject($subject); } }
/** * {@inheritdoc} */ protected function executeAction($context) { $emailModel = new Email(); $from = $this->getEmailAddress($context, $this->options['from']); $this->validateAddress($from); $emailModel->setFrom($from); $to = []; foreach ($this->options['to'] as $email) { if ($email) { $address = $this->getEmailAddress($context, $email); $this->validateAddress($address); $to[] = $this->getEmailAddress($context, $address); } } $emailModel->setTo($to); $entity = $this->contextAccessor->getValue($context, $this->options['entity']); $template = $this->contextAccessor->getValue($context, $this->options['template']); $emailTemplate = $this->objectManager->getRepository('OroEmailBundle:EmailTemplate')->findByName($template); if (!$emailTemplate) { $errorMessage = sprintf('Template "%s" not found.', $template); $this->logger->error('Workflow send email action.' . $errorMessage); throw new EntityNotFoundException($errorMessage); } $templateData = $this->renderer->compileMessage($emailTemplate, ['entity' => $entity]); $type = $emailTemplate->getType() == 'txt' ? 'text/plain' : 'text/html'; list($subjectRendered, $templateRendered) = $templateData; $emailModel->setSubject($subjectRendered); $emailModel->setBody($templateRendered); $emailModel->setType($type); $emailUser = $this->emailProcessor->process($emailModel); if (array_key_exists('attribute', $this->options)) { $this->contextAccessor->setValue($context, $this->options['attribute'], $emailUser->getEmail()); } }
/** * @param EmailModel $emailModel * @param EmailTemplate $template * @param Email $email */ protected function applyTemplate(EmailModel $emailModel, EmailTemplate $template, Email $email) { $locales = array_merge($email->getAcceptedLocales(), [$this->defaultLocale]); $flippedLocales = array_flip($locales); $translatedSubjects = []; $translatedContents = []; foreach ($template->getTranslations() as $translation) { switch ($translation->getField()) { case 'content': $translatedContents[$translation->getLocale()] = $translation->getContent(); break; case 'subject': $translatedSubjects[$translation->getLocale()] = $translation->getContent(); break; } } $comparator = ArrayUtil::createOrderedComparator($flippedLocales); uksort($translatedSubjects, $comparator); uksort($translatedContents, $comparator); $validContents = array_intersect_key($translatedContents, $flippedLocales); $validsubjects = array_intersect_key($translatedSubjects, $flippedLocales); $content = reset($validContents); $subject = reset($validsubjects); $emailModel->setSubject($subject === false ? $template->getSubject() : $subject)->setBody($content === false ? $template->getContent() : $content)->setType($template->getType()); }
/** * Populate a model with initial data. * This method is used to load an initial data from a query string * * @param Email $model */ protected function initModel(Email $model) { if ($this->request->query->has('gridName')) { $model->setGridName($this->request->query->get('gridName')); } if ($this->request->query->has('from')) { $from = $this->request->query->get('from'); if (!empty($from)) { $this->preciseFullEmailAddress($from); } $model->setFrom($from); } else { $user = $this->getUser(); if ($user) { $model->setFrom(EmailUtil::buildFullEmailAddress($user->getEmail(), $this->nameFormatter->format($user))); } } if ($this->request->query->has('to')) { $to = trim($this->request->query->get('to')); if (!empty($to)) { $this->preciseFullEmailAddress($to); } $model->setTo(array($to)); } if ($this->request->query->has('subject')) { $subject = trim($this->request->query->get('subject')); $model->setSubject($subject); } }
/** * Populate a model with initial data. * This method is used to load an initial data from a query string * * @param Email $model */ protected function initModel(Email $model) { if ($this->request->query->has('gridName')) { $model->setGridName($this->request->query->get('gridName')); } if ($this->request->query->has('entityClass')) { $model->setEntityClass($this->entityRoutingHelper->decodeClassName($this->request->query->get('entityClass'))); } if ($this->request->query->has('entityId')) { $model->setEntityId($this->request->query->get('entityId')); } if ($this->request->query->has('from')) { $from = $this->request->query->get('from'); if (!empty($from)) { $this->preciseFullEmailAddress($from); } $model->setFrom($from); } else { $user = $this->getUser(); if ($user) { $model->setFrom($this->emailAddressHelper->buildFullEmailAddress($user->getEmail(), $this->nameFormatter->format($user))); } } if ($this->request->query->has('to')) { $to = trim($this->request->query->get('to')); if (!empty($to)) { $this->preciseFullEmailAddress($to, $model->getEntityClass(), $model->getEntityId()); } $model->setTo(array($to)); } if ($this->request->query->has('subject')) { $subject = trim($this->request->query->get('subject')); $model->setSubject($subject); } }
/** * {@inheritdoc} */ protected function executeAction($context) { $emailModel = new Email(); $emailModel->setFrom($this->getEmailAddress($context, $this->options['from'])); $to = array(); foreach ($this->options['to'] as $email) { if ($email) { $to[] = $this->getEmailAddress($context, $email); } } $emailModel->setTo($to); $emailModel->setSubject($this->contextAccessor->getValue($context, $this->options['subject'])); $emailModel->setBody($this->contextAccessor->getValue($context, $this->options['body'])); $email = $this->emailProcessor->process($emailModel); if (array_key_exists('attribute', $this->options)) { $this->contextAccessor->setValue($context, $this->options['attribute'], $email); } }