Problem/Motivation

A similar issue was already posted but the integrated fix does not work of you send HTML mails with links.
https://www.drupal.org/project/registration/issues/3346373

I think the proposed solution to use renderPlain() does not solve the issue.

In our case the following errors appears while processing the queue via cron:

 [error]  LogicException: Render context is empty, because render() was called outside of a renderRoot() or renderPlain() call. Use renderPlain()/renderRoot() or #lazy_builder/#pre_render instead. in Drupal\Core\Render\Renderer->doRender() (line 251 of /app/docroot/core/lib/Drupal/Core/Render/Renderer.php).

Steps to reproduce

Send out HTML email using the reminder mail via cron.

Proposed resolution

The correct approach to omit these kind of logic exception is to render the mail inside a render context.

Attached a patch, that does exactly this and resolves the issue.

Comments

ayalon created an issue. See original summary.

ayalon’s picture

john.oltman’s picture

Status: Active » Closed (duplicate)
Related issues: +#3346373: Reminder emails generate fatal error when triggered via drush cron

This was addressed in https://www.drupal.org/project/registration/issues/3346373

Please install the latest release and see if it solves the issue. If it doesn't, that other issue should be re-opened.

I am guessing, if you are using the dev branch, that it is pinned to an older release of dev. You should try rc-1 instead of dev. The error message implies the call is made "outside of renderPlain", and that other issue switched to a renderPlain, so the error message you are reporting does not jive with the patch you supplied.

Sorry - I did not read your original post correctly. I am still confused by the error message. Can you confirm the release you are using? The error message implies that the module is not using renderPlain - but renderPlain is in fact being used. I am surprised that an HTML email with a link would behave differently than one without.

Re-opening this issue for now. Again, my apologies for misreading your original post.

john.oltman’s picture

Title: Exception when seinding reminder mails via cron » Exception when sending HTML reminder emails with links via cron
ayalon’s picture

I can confirm, that this error happens with the release that is using renderPlain().

I think, calling "new FormattableMarkup()" raises the issue as well and therefore I have wrapped it into a renderContext and reverted renderPlain to render.

john.oltman’s picture

Thanks for confirming the release. renderPlain creates a render context and uses it for rendering, so I'll have to dig into this further to see why that would not be sufficient for what you are doing. You wouldn't happen to have a full stack trace by chance would you. I would like to be sure that the render that is failing is from the Registration module. It could be that some other module or custom code is doing early rendering without a context when creating its render array - and somehow your patch covers that up. Still a mystery at this point.

john.oltman’s picture

Also @ayalon if possible could you post the HTML source of your reminder email here or to my D.org account contact page, so I can try and reproduce the issue in my test environment. I would like to see it fail, and then see how the patch fixes it, in my debugger.

john.oltman’s picture

Status: Active » Postponed (maintainer needs more info)
john.oltman’s picture

john.oltman’s picture

john.oltman’s picture

john.oltman’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)