We're migrating some code to D8 and in some of our nodes' body field we used to call PHP code directly with the now defunct
module_invoke to render a block in the node before the content.
All the examples I can find explain how to do that in D8 with themes or templates, but I need to render the block inside the node body using PHP code, is there a way to do that?
We already tried:
\Drupal::moduleHandler()->invoke($module, $hook, $args = array())
but it doesn't show the block, presumably because it only takes modules?
From this answer we also tried:
$block = \Drupal\block_content\Entity\BlockContent::load($bid); $render = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block);
Trying to print or render
$render either doesn't show anything or literally prints out an array.