LogicException: Render context is empty, because render() was called outside of a renderRoot() or renderPlain() call

Created on 14 February 2023, almost 2 years ago
Updated 15 February 2023, almost 2 years ago

Problem/Motivation

When running a task in a hook_cron() implementation that has a call to save a node, the smart_date_recur module has registered tokens (via a hook_token() implementation.) If the node has a smart date field then the token tries to use Drupal's Renderer::render() to render the output. This results in an error message as follows:

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()

Steps to reproduce

  • Create a node with a smart date
  • Create an implementation of hook_cron() somewhere and load a node then save it again using the Node/Entity API.
  • Importantly: Run cron via drush (e.g. drush cron). The above error does not reproduce if cron is run through Drupal's admin UI

Proposed resolution

Convert calls to Renderer::render() to Renderer::renderPlain()

Remaining tasks

I've got a working version of the sub-module with two small working edits. Merge request made. See comment thread.

User interface changes

None

API changes

None - although would good to have some community testing as not sure if this has an impact I'm not aware of.

Data model changes

None

🐛 Bug report
Status

Fixed

Version

3.7

Component

Smart Date Recur

Created by

🇬🇧United Kingdom barry_fisher

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024