Skip to content

Commit

Permalink
Fix email rendering when using 2 different plugins.
Browse files Browse the repository at this point in the history
When an email template and layout are in different plugins the incorrect
plugin would be used for the layout.

Fixes #3062
  • Loading branch information
markstory committed Apr 5, 2014
1 parent b8e21c9 commit 4ec8154
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
14 changes: 7 additions & 7 deletions lib/Cake/Network/Email/CakeEmail.php
Expand Up @@ -1638,21 +1638,21 @@ protected function _renderTemplates($content) {
$View->plugin = $layoutPlugin;
}

// Convert null to false, as View needs false to disable
// the layout.
if ($layout === null) {
$layout = false;
}

if ($View->get('content') === null) {
$View->set('content', $content);
}

// Convert null to false, as View needs false to disable
// the layout.
if ($this->_layout === null) {
$this->_layout = false;
}

foreach ($types as $type) {
$View->hasRendered = false;
$View->viewPath = $View->layoutPath = 'Emails' . DS . $type;

$render = $View->render($template, $layout);
$render = $View->render($this->_template, $this->_layout);
$render = str_replace(array("\r\n", "\r"), "\n", $render);
$rendered[$type] = $this->_encodeString($render, $this->charset);
}
Expand Down
10 changes: 9 additions & 1 deletion lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
Expand Up @@ -1472,7 +1472,7 @@ public function testSendRenderPlugin() {
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
));
CakePlugin::load('TestPlugin');
CakePlugin::load(array('TestPlugin', 'TestPluginTwo'));

$this->CakeEmail->reset();
$this->CakeEmail->transport('debug');
Expand All @@ -1493,6 +1493,14 @@ public function testSendRenderPlugin() {
$this->assertContains('Into TestPlugin.', $result['message']);
$this->assertContains('This email was sent using the TestPlugin.', $result['message']);

$this->CakeEmail->template(
'TestPlugin.test_plugin_tpl',
'TestPluginTwo.default'
);
$result = $this->CakeEmail->send();
$this->assertContains('Into TestPlugin.', $result['message']);
$this->assertContains('This email was sent using TestPluginTwo.', $result['message']);

// test plugin template overridden by theme
$this->CakeEmail->theme('TestTheme');
$result = $this->CakeEmail->send();
Expand Down

0 comments on commit 4ec8154

Please sign in to comment.