You are here

private function ReusableBlockFilter::renderBlock in Gutenberg 8

Callback function to process each block.

File

src/Plugin/Filter/ReusableBlockFilter.php, line 39

Class

ReusableBlockFilter
Class ReusableBlockFilter.

Namespace

Drupal\gutenberg\Plugin\Filter

Code

private function renderBlock($match) {
  $block = NULL;
  $comment = $match[0];
  $attributes = json_decode($match[1]);
  if (!empty($attributes->ref)) {
    $bid = $attributes->ref;
    $block = BlockContent::load($bid);
  }
  if (!$block) {
    return $comment;
  }
  $render = \Drupal::entityTypeManager()
    ->getViewBuilder('block_content')
    ->view($block, 'reusable_block');
  $content = \Drupal::service('renderer')
    ->render($render);
  return $comment . $content;
}