In order to send html email using drupal/swiftmailer I load and view a node.
Then I pass it to the rendere. In the email sent, generated node__links are empty. As node_links uses #LazyBuilder, Im then not sure to use the correct way.
hook_mail
function mymodule_mail($key, &$message, $params) {
switch ($key) {
case 'mail_node':
$message['from'] = \Drupal::config('system.site')->get('mail');
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed; delsp=yes';
$message['subject'] = t('Mail subject');
$node = Node::load($params['nid']);
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
$body_data = [
'#theme' => 'mymodule_mail_node',
'#content' => $view_builder->view( $node ),
];
$message['body'][] = \Drupal::service('renderer')->render($body_data);
break;
}
}
mymodule--mail-node.html.twig
{# simply render the whole body #}
{{ body }}
output results in mail
<!-- THEME DEBUG -->
<!-- THEME HOOK: 'links__node' -->
<!-- FILE NAME SUGGESTIONS:
x links--node.html.twig
* links.html.twig
-->
<!-- BEGIN OUTPUT from 'core/themes/classy/templates/content/links--node.html.twig' -->
<!-- END OUTPUT from 'core/themes/classy/templates/content/links--node.html.twig' -->
When I render the same content into an html page, node__links are correctly filled.
Any recommandation would be appreciate. Thanks