Problem/Motivation

In token_requirements, problems are output as follows:

$requirements['token-' . $problem_key] = array(
  'title' => $problem['label'],
  // @todo Use render arrays. See https://drupal.org/node/2195739
  'value' => \Drupal::theme()->render('item_list', array('items' => $problems)),
  'severity' => $problem['severity'],
);

This works fine on the requirements page, where the list of requirements is being rendered. However, when calling SystemManager::listRequirements() during hook_cron, for example, this causes an Exception:

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

Proposed resolution

From what I can see in the documentation for renderRoot and renderPlain, using renderPlain is probably the best option in this case. We can also use this time to fix the todo in the code above.

I'll attach a patch right away.

CommentFileSizeAuthor
#2 token_requirements-2686959-2.patch888 bytesMirroar

Comments

Mirroar created an issue. See original summary.

Mirroar’s picture

Status: Active » Needs review
StatusFileSize
new888 bytes

And here's the patch I'd suggest.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Makes sense, thanks.

  • Berdir committed 2162626 on 8.x-1.x authored by Mirroar
    Issue #2686959 by Mirroar: token_requirements should not call...
berdir’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.