class ReusableBlockProcessor in Gutenberg 8.2
Processes Gutenberg reusable blocks.
Hierarchy
- class \Drupal\gutenberg\BlockProcessor\ReusableBlockProcessor implements GutenbergBlockProcessorInterface
Expanded class hierarchy of ReusableBlockProcessor
1 string reference to 'ReusableBlockProcessor'
1 service uses ReusableBlockProcessor
File
- src/
BlockProcessor/ ReusableBlockProcessor.php, line 15
Namespace
Drupal\gutenberg\BlockProcessorView source
class ReusableBlockProcessor implements GutenbergBlockProcessorInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Drupal\Core\Render\RendererInterface instance.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* The Gutenberg logger.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* ReusableBlockProcessor constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
* @param \Psr\Log\LoggerInterface $logger
* Gutenberg logger interface.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer, LoggerInterface $logger) {
$this->entityTypeManager = $entity_type_manager;
$this->renderer = $renderer;
$this->logger = $logger;
}
/**
* {@inheritdoc}
*/
public function processBlock(array &$block, &$block_content, RefinableCacheableDependencyInterface $bubbleable_metadata) {
$block_attributes = $block['attrs'];
if (empty($block_attributes['ref'])) {
// This should not happen, and typically means there's a bug somewhere.
$this->logger
->error('Missing reusable block reference ID.');
return;
}
$bid = $block_attributes['ref'];
$block_entity = BlockContent::load($bid);
if ($block_entity) {
$render = $this->entityTypeManager
->getViewBuilder('block_content')
->view($block_entity, 'reusable_block');
$block_content = $this->renderer
->render($render);
$bubbleable_metadata
->addCacheableDependency(CacheableMetadata::createFromRenderArray($render));
}
}
/**
* {@inheritdoc}
*/
public function isSupported(array $block, $block_content = '') {
return $block['blockName'] === 'core/block';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ReusableBlockProcessor:: |
protected | property | The entity type manager. | |
ReusableBlockProcessor:: |
protected | property | The Gutenberg logger. | |
ReusableBlockProcessor:: |
protected | property | Drupal\Core\Render\RendererInterface instance. | |
ReusableBlockProcessor:: |
public | function |
Whether the processor supports this block instance. Overrides GutenbergBlockProcessorInterface:: |
|
ReusableBlockProcessor:: |
public | function |
Process the Gutenberg block and its content. Overrides GutenbergBlockProcessorInterface:: |
|
ReusableBlockProcessor:: |
public | function | ReusableBlockProcessor constructor. |