Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] Add template theme to mail notifications #29132

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add ability to set theme for mail notifications
We already can set a different theme than the default one for our
Mailable. It would be very useful if there was a way to set the theme
for the mail notifications too.
  • Loading branch information
Giulio Troccoli-Allard committed Jul 10, 2019
commit aed06b10f44b24928aeffa589f630bf5b5c19ed8
4 changes: 4 additions & 0 deletions src/Illuminate/Notifications/Channels/MailChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ protected function buildView($message)
return $message->view;
}

if (property_exists($message, 'theme') && ! is_null($message->theme)) {
$this->markdown->theme($message->theme);
}

return [
'html' => $this->markdown->render($message->markdown, $message->data()),
'text' => $this->markdown->renderText($message->markdown, $message->data()),
Expand Down
20 changes: 20 additions & 0 deletions src/Illuminate/Notifications/Messages/MailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class MailMessage extends SimpleMessage implements Renderable
*/
public $markdown = 'notifications::email';

/**
* The current theme being used when generating emails.
*
* @var string|null
*/
public $theme = 'default';

/**
* The "from" information for the message.
*
Expand Down Expand Up @@ -134,6 +141,19 @@ public function template($template)
return $this;
}

/**
* Set the theme to use with the markdown template.
*
* @param string $theme
* @return $this
*/
public function theme($theme)
{
$this->theme = $theme;

return $this;
}

/**
* Set the from address for the mail message.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function test_mail_is_sent()
'email' => '[email protected]',
]);

$this->markdown->shouldReceive('theme')->once()->andReturnSelf();
$this->markdown->shouldReceive('render')->once()->andReturn('htmlContent');
$this->markdown->shouldReceive('renderText')->once()->andReturn('textContent');

Expand Down Expand Up @@ -118,6 +119,7 @@ public function test_mail_is_sent_to_named_address()
'name' => 'Taylor Otwell',
]);

$this->markdown->shouldReceive('theme')->once()->andReturnSelf();
$this->markdown->shouldReceive('render')->once()->andReturn('htmlContent');
$this->markdown->shouldReceive('renderText')->once()->andReturn('textContent');

Expand Down Expand Up @@ -161,6 +163,7 @@ public function test_mail_is_sent_with_subject()
'email' => '[email protected]',
]);

$this->markdown->shouldReceive('theme')->once()->andReturnSelf();
$this->markdown->shouldReceive('render')->once()->andReturn('htmlContent');
$this->markdown->shouldReceive('renderText')->once()->andReturn('textContent');

Expand Down Expand Up @@ -194,6 +197,7 @@ public function test_mail_is_sent_to_multiple_adresses()
'email' => '[email protected]',
]);

$this->markdown->shouldReceive('theme')->once()->andReturnSelf();
$this->markdown->shouldReceive('render')->once()->andReturn('htmlContent');
$this->markdown->shouldReceive('renderText')->once()->andReturn('textContent');

Expand Down