I have a render array and I want to convert it to HTML and place it in a WYSIWYG field. What is the generally accepted way to do that since drupal_render() is deprecated?
$render_service = \Drupal::service('renderer');
As mpdonadio and 4k4 have pointed out in the comments, to prevent metadata from bubbling up to the main request, you should execute this in a new render context. You can do so by using the
renderPlain method, rather than the usual
render method (unless you're returning this from a controller, in which case use
$rendered = $render_service->renderPlain($build);