-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from johnkrovitch/bugfix/email-sending
Fix the email sending when a new comment is added and improve the mail parameters naming
- Loading branch information
Showing
6 changed files
with
34 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,9 +81,11 @@ private function configureEmailNode(NodeBuilder $builder): void | |
$builder | ||
->arrayNode('email') | ||
->addDefaultsIfNotSet() | ||
->isRequired() | ||
->children() | ||
->scalarNode('base_template')->defaultValue('@JKCms/Mail/base.html.twig')->end() | ||
->scalarNode('contact_email')->defaultValue('[email protected]')->end() | ||
->scalarNode('from')->defaultValue('[email protected]')->cannotBeEmpty()->end() | ||
->scalarNode('to')->defaultValue('[email protected]')->cannotBeEmpty()->end() | ||
->end() | ||
->end() | ||
; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ class AddCommentHandler | |
/** | ||
* @var string | ||
*/ | ||
private $contactEmail; | ||
private $fromEmail; | ||
|
||
/** | ||
* @var TranslatorInterface | ||
|
@@ -50,8 +50,14 @@ class AddCommentHandler | |
*/ | ||
private $router; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $toEmail; | ||
|
||
public function __construct( | ||
string $contactEmail, | ||
string $fromEmail, | ||
string $toEmail, | ||
CommentManagerInterface $manager, | ||
TranslatorInterface $translator, | ||
MailerInterface $mailer, | ||
|
@@ -60,12 +66,13 @@ public function __construct( | |
RouterInterface $router | ||
) { | ||
$this->manager = $manager; | ||
$this->contactEmail = $contactEmail; | ||
$this->fromEmail = $fromEmail; | ||
$this->translator = $translator; | ||
$this->mailer = $mailer; | ||
$this->helper = $helper; | ||
$this->environment = $environment; | ||
$this->router = $router; | ||
$this->toEmail = $toEmail; | ||
} | ||
|
||
public function handle(array $data, Article $article): void | ||
|
@@ -85,11 +92,6 @@ public function handle(array $data, Article $article): void | |
|
||
private function sendEmail(Comment $comment): void | ||
{ | ||
$from = $comment->getAuthorEmail(); | ||
|
||
if (!$from) { | ||
$from = '[email protected]'; | ||
} | ||
$subject = $this->translator->trans('cms.new_comment.subject', [ | ||
':application' => $this->helper->getApplicationName(), | ||
':article' => $comment->getArticle()->getTitle(), | ||
|
@@ -101,8 +103,8 @@ private function sendEmail(Comment $comment): void | |
], 'mailing'); | ||
|
||
$email = (new NotificationEmail()) | ||
->from($from) | ||
->to($this->contactEmail) | ||
->from($this->toEmail) | ||
->to($this->fromEmail) | ||
->subject($subject) | ||
->markdown($message) | ||
->importance(NotificationEmail::IMPORTANCE_MEDIUM) | ||
|
@@ -122,6 +124,9 @@ private function getShowRouteParameters(Article $article): array | |
$parameters = []; | ||
|
||
foreach ($this->helper->getShowRouteParameters() as $name => $property) { | ||
if (null === $property) { | ||
$property = $name; | ||
} | ||
$parameters[$name] = $accessor->getValue($article, $property); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,9 @@ jk_cms: | |
preview_route: test.article.preview | ||
preview_route_parameters: | ||
id: ~ | ||
email: | ||
from: [email protected] | ||
to: [email protected] | ||
|
||
framework: | ||
secret: 'yes' | ||
|