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
[10.x] Support Inline Attachments within Markdown Mailable #47603
[10.x] Support Inline Attachments within Markdown Mailable #47603
Conversation
@cosmastech Can you explain me why #47140 didn't not solve this problem? |
For parity, in this MR, we changed Let me know if that makes sense @nunomaduro |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I am little bit rusty on this. Can you tell me how can I locally reproduce the issue this pull request is solving?
@@ -100,8 +100,8 @@ protected function buildView($message) | |||
} | |||
|
|||
return [ | |||
'html' => $this->markdown->render($message->markdown, $message->data()), | |||
'text' => $this->markdown->renderText($message->markdown, $message->data()), | |||
'html' => fn ($messageData = []) => $this->markdown->render($message->markdown, $messageData), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my pull request, we've moved the "markdown->theme($message->theme)" to be executed within the given closure. Shouldn't we do the same here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like theme is respected if I write return (new MailMessage)->markdown('markdown')->theme('abba-zabba');
within the toMail() method of the notification.
That said, the instance level $markdown should be cloned, since we are changing the theme. Though Markdown is not bound as a singleton in the container, subsequent calls would use the same theme, even tho the user would anticipate it to be the result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But can you adjust the code, so the "set" of theme happens exactly before the rendering? Just like the code I've done for the other PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nunomaduro take a look at how I have implemented it with the latest 2 commits. I can move it into the closure if that's better, but I don't see any way that the message's theme property would be overridden. (Also, I just think it would look uglier).
Could we remove the Markdown instance variable and just create it within the closures (or buildView()
method)? It would mean a signature change to the constructor, but that instance level variable is more of a hinderance than a help, IMO.
#47592 describes how to set this up. |
* We clone the Markdown instance so that setting a theme doesn't | ||
* carry over to subsequent calls to build the view. | ||
*/ | ||
$markdown = clone $this->markdown; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather to have an implementation exactly like my pull request, and simply access the instance of markdown ($this->markdown
) within the closure, to set the theme based on the message, right before call the renders.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added what I think you requested. If the code changes look good, I can go and fix the tests that are failing due to Mockery expectations.
That said, I respectfully disagree with this approach. Why even bother passing a default theme to the Markdown class if we are always going to manually fetch the markdown theme from config() every time it's used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this would be better if there was a PendingRender class or something. Maybe an idea for 11.x
Merging this against a branch of mine, so I can make some adjustments and test it myself. Thanks! |
969c9fe
into
laravel:fix/markdown-mailable-adjustments
to close #47592
If using a view for building a message, the actual rendering of the view into HTML doesn't happen until later in the process, where it has the Message object (which has the
embed()
method) for use within the View. When using markdown instead, the process was happening before calling Mailer@send().By converting these two to closures, we allow for the markdown component to be built within Mailer@renderView() instead (which passes the message data as an array).
Note that there were some unrelated tests which needed updating. This was only to accommodate how those tests' expectations were set up.