Skip to content

Commit

Permalink
Fixed configuration of plain text email templates (#201)
Browse files Browse the repository at this point in the history
* Fixed configuration of plain text email templates

* Updated CHANGELOG

* Added methods to type interface

* Use template variable in plaintext method
  • Loading branch information
thomasduenser authored and alexander-schranz committed Sep 12, 2019
1 parent c4a8434 commit cc2a6bb
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.1

- BUGFIX #201 Fix configuration of plain text emails

## 1.0.0

- No changes
Expand Down
2 changes: 2 additions & 0 deletions Configuration/FormConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ private function buildAdminMailConfigurationByTypeAndData(AbstractType $type, $f
$adminMailConfiguration->setReplyTo($type->getNotifyReplyToMailAddress($formData));
$adminMailConfiguration->setAddAttachments($type->getNotifySendAttachments($formData));
$adminMailConfiguration->setTemplate($type->getNotifyMail($formData));
$adminMailConfiguration->setPlainTextTemplate($type->getNotifyPlainMail($formData));
$adminMailConfiguration->setTemplateAttributes($attributes);

return $adminMailConfiguration;
Expand Down Expand Up @@ -180,6 +181,7 @@ private function buildWebsiteMailConfigurationByTypeAndData(AbstractType $type,
$websiteMailConfiguration->setReplyTo($type->getCustomerReplyToMailAddress($formData));
$websiteMailConfiguration->setAddAttachments(false); // Currently not implemented in the AbstractType.
$websiteMailConfiguration->setTemplate($type->getCustomerMail($formData));
$websiteMailConfiguration->setPlainTextTemplate($type->getCustomerPlainMail($formData));
$websiteMailConfiguration->setTemplateAttributes($attributes);

return $websiteMailConfiguration;
Expand Down
9 changes: 8 additions & 1 deletion Form/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,22 @@ protected function getMediaData(

/**
* Get plain text variant for email, overridable and customizable per form.
*
* @param FormInterface $form
* @param MailConfigurationInterface $configuration
* @param array $additionalData
* @return string
*/
protected function getPlainText(FormInterface $form, MailConfigurationInterface $configuration, array $additionalData)
{
$template = $configuration->getPlainTextTemplate();

if (!$template) {
return null;
}

return $this->templating->render(
$configuration->getPlainTextTemplate(),
$template,
array_merge(
$configuration->getTemplateAttributes(),
$additionalData
Expand Down
16 changes: 16 additions & 0 deletions Form/Type/AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ public function getNotifyMail($formData = [])
return 'ClientWebsiteBundle:views:form/mail/' . $this->getName() . '/notify.html.twig';
}

/**
* {@inheritdoc}
*/
public function getCustomerPlainMail($formData = [])
{
return null;
}

/**
* {@inheritdoc}
*/
public function getNotifyPlainMail($formData = [])
{
return null;
}

/**
* {@inheritdoc}
*/
Expand Down
10 changes: 10 additions & 0 deletions Form/Type/TypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ public function getCustomerMail($formData = []);
*/
public function getNotifyMail($formData = []);

/**
* {@inheritdoc}
*/
public function getCustomerPlainMail($formData = []);

/**
* {@inheritdoc}
*/
public function getNotifyPlainMail($formData = []);

/**
* @param $formData
*
Expand Down

0 comments on commit cc2a6bb

Please sign in to comment.