public function DynamicRenderProcessor::processBlock in Gutenberg 8.2
Process the Gutenberg block and its content.
The content and block can be manipulated here. Return FALSE to ensure that no other plugins are ran after this instance.
Parameters
array $block: The block object.
string $block_content: The inner block content.
\Drupal\Core\Cache\RefinableCacheableDependencyInterface $bubbleable_metadata: The bubbleable metadata.
Return value
bool|null Return FALSE if further processing should be stopped.
Overrides GutenbergBlockProcessorInterface::processBlock
File
- src/
BlockProcessor/ DynamicRenderProcessor.php, line 68
Class
- DynamicRenderProcessor
- Processes blocks which can be rendered dynamically server-side.
Namespace
Drupal\gutenberg\BlockProcessorCode
public function processBlock(array &$block, &$block_content, RefinableCacheableDependencyInterface $bubbleable_metadata) {
$build = [
'#theme' => 'gutenberg_block',
'#block_name' => $block['blockName'],
'#block_attributes' => $block['attrs'],
'#block_content' => [
// TODO @codebymikey: Review whether this might be susceptible to XSS.
// I don't think it should.
'#markup' => Markup::create($block_content),
],
'#pre_render' => [],
];
// If an alter hook wants to modify the block contents, it can append
// several #pre_render hooks, or appropriate #cache tags.
$block_name = str_replace('-', '_', $block['blockName']);
$block_parts = explode('/', $block_name);
$hooks = [
'gutenberg_block_view',
];
$base_hook = 'gutenberg_block_view__';
$hooks[] = $base_hook . $block_parts[0];
if (count($block_parts) === 2) {
// namespace/blockname format.
$hooks[] = $base_hook . $block_parts[0] . '__' . $block_parts[1];
}
$this->moduleHandler
->alter($hooks, $build, $block_content);
$block_content = $this->renderer
->render($build);
$bubbleable_metadata
->addCacheableDependency(CacheableMetadata::createFromRenderArray($build));
}