private function ContentEntityViewModesExtractor::getBlockMinimalBuildArray in Acquia Content Hub 8
Renders block using BlockViewBuilder.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $object: The Content Entity Object.
string $view_mode: The request view mode identifier.
Return value
array Render array for the block.
1 call to ContentEntityViewModesExtractor::getBlockMinimalBuildArray()
- ContentEntityViewModesExtractor::getViewModeMinimalHtml in src/
Normalizer/ ContentEntityViewModesExtractor.php - Renders all the view modes that are configured to be rendered.
File
- src/
Normalizer/ ContentEntityViewModesExtractor.php, line 376
Class
- ContentEntityViewModesExtractor
- Extracts the rendered view modes from a given ContentEntity Object.
Namespace
Drupal\acquia_contenthub\NormalizerCode
private function getBlockMinimalBuildArray(ContentEntityInterface $object, $view_mode) {
/** @var \Drupal\entity_block\Plugin\Block\EntityBlock $block */
$block = $this->blockManager
->createInstance('block_content:' . $object
->uuid());
$build = [
'#theme' => 'block',
'#attributes' => [],
'#contextual_links' => [],
'#weight' => 0,
'#configuration' => $block
->getConfiguration(),
'#plugin_id' => $block
->getPluginId(),
'#base_plugin_id' => $block
->getBaseId(),
'#derivative_plugin_id' => $block
->getDerivativeId(),
];
// Label controlled by the block__block_content__acquia_contenthub template
// (hidden by default). Override the template in your theme to render a
// block label.
if ($build['#configuration']['label'] === '') {
$build['#configuration']['label'] = $block
->label();
}
// Block entity itself doesn't have configuration.
$block
->setConfigurationValue('view_mode', $view_mode);
$build['#configuration']['view_mode'] = $view_mode;
// See \Drupal\block\BlockViewBuilder::preRender() for reference.
$content = $block
->build();
if ($content !== NULL && !Element::isEmpty($content)) {
foreach ([
'#attributes',
'#contextual_links',
] as $property) {
if (isset($content[$property])) {
$build[$property] += $content[$property];
unset($content[$property]);
}
}
}
$build['content'] = $content;
return $build;
}