You are here

protected function GutenbergFilter::renderBlock in Gutenberg 8.2

Render a Gutenberg block.

Parameters

array $block: The Gutenberg block.

\Drupal\Core\Cache\RefinableCacheableDependencyInterface $bubbleable_metadata: The bubbleable metadata.

Return value

string The block content.

1 call to GutenbergFilter::renderBlock()
GutenbergFilter::process in src/Plugin/Filter/GutenbergFilter.php

File

src/Plugin/Filter/GutenbergFilter.php, line 182

Class

GutenbergFilter
Provides a filter for Gutenberg blocks.

Namespace

Drupal\gutenberg\Plugin\Filter

Code

protected function renderBlock(array $block, RefinableCacheableDependencyInterface $bubbleable_metadata) {
  $index = 0;
  $block_content = '';
  foreach ($block['innerContent'] as $chunk) {
    if (is_string($chunk)) {
      $block_content .= $chunk;
    }
    else {
      $block_content .= $this
        ->renderBlock($block['innerBlocks'][$index++], $bubbleable_metadata);
    }
  }
  $processors = $this->blockProcessorManager
    ->getSortedProcessors();
  foreach ($processors as $processor) {
    if ($processor
      ->isSupported($block, $block_content)) {
      $result = $processor
        ->processBlock($block, $block_content, $bubbleable_metadata);
      if ($result === FALSE) {

        // Stop further processing of the block.
        break;
      }
    }
  }
  return $block_content;
}