I wonder what's the right way to render entity render array as a token replacement (value). I found 3 different ways in the contrib:
- using
render
method: https://git.drupalcode.org/project/aet/-/blob/2.x/src/TokenReplacer.php#L556 - using
renderPlain()
method: https://git.drupalcode.org/project/token_entity_render/-/blob/2.0.x/token_entity_render.module#L83 - using
renderRoot()
method: https://github.com/goalgorilla/open_social/blob/345bec4e8277e2d2049e2c975eda96f823bfc478/modules/social_features/social_event/social_event.tokens.inc#L160 This last one seems to be causingLogicException: A stray renderRoot() invocation is causing bubbling of attached assets to break. v Drupal\Core\Render\Renderer->renderRoot()
error in some circumstances.
Looking at https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21Renderer.php/function/Renderer%3A%3ArenderPlain/9.3.x, it looks like this method should be the correct one, given the description:
Useful for instance when rendering the values of tokens or emails, which need a render array being turned into a string
Is that true?