Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 8 additions & 9 deletions src/Mailer/PreviewResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
namespace DebugKit\Mailer;

use Cake\Mailer\Mailer;
use Cake\Mailer\Renderer;
use ReflectionClass;
use Cake\Mailer\Message;

/**
* Represents the result of a preview for a given mailer
Expand Down Expand Up @@ -47,14 +46,14 @@ protected function processMailer(Mailer $mailer, $method)
$mailer->viewBuilder()->setTemplate($method);
}

$reflection = new ReflectionClass($mailer);
$prop = $reflection->getProperty('_email');
$prop->setAccessible(true);
$email = $prop->getValue($mailer);

$this->parts = $email->getRenderer()->renderTemplates($email, '');
$mailer->render();
$message = $mailer->getMessage();
$this->parts = [
'html' => $message->getBody(Message::MESSAGE_HTML),
'text' => $message->getBody(Message::MESSAGE_TEXT),
];

$extra = ['from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'subject'];
$this->headers = array_filter($email->getHeaders($extra));
$this->headers = array_filter($message->getHeaders($extra));
}
}
2 changes: 1 addition & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function bootstrap(PluginApplicationInterface $app): void
public function middleware(MiddlewareQueue $middleware): MiddlewareQueue
{
if ($this->service) {
$middleware->add(new DebugKitMiddleware($this->service));
$middleware->insertAt(0, new DebugKitMiddleware($this->service));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lets the toolbar display again 👍

}

return $middleware;
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Controller/MailPreviewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function testEmailPluginPassedToView()
$this->get('/debug-kit/mail-preview/preview/TestMailerPreview/test_email?plugin=DebugkitTestPlugin');

$this->assertResponseOk();
$this->assertResponseContains('src="?part=text&plugin=DebugkitTestPlugin');
$this->assertResponseContains('src="?part=html&plugin=DebugkitTestPlugin');
}

/** Test email template content
Expand Down