Skip to content

Commit

Permalink
Merge pull request #29132 from troccoli/add-template-theme-to-mail-no…
Browse files Browse the repository at this point in the history
…tifications

[5.8] Add template theme to mail notifications
  • Loading branch information
taylorotwell authored Jul 11, 2019
2 parents bb5ba2d + aed06b1 commit 2e96129
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
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

0 comments on commit 2e96129

Please sign in to comment.