class BlockContentViewBuilder
Same name and namespace in other branches
- 11.x core/modules/block_content/src/BlockContentViewBuilder.php \Drupal\block_content\BlockContentViewBuilder
View builder handler for custom blocks.
Note: Custom blocks (block_content entities) are not designed to be displayed outside of blocks! This BlockContentViewBuilder class is designed to be used by \Drupal\block_content\Plugin\Block\BlockContentBlock::build() and by nothing else.
Hierarchy
- class \Drupal\Core\Entity\EntityHandlerBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait
- class \Drupal\Core\Entity\EntityViewBuilder extends \Drupal\Core\Entity\EntityHandlerInterface, \Drupal\Core\Entity\EntityViewBuilderInterface, \Drupal\Core\Security\TrustedCallbackInterface implements \Drupal\Core\Entity\EntityHandlerBase
- class \Drupal\block_content\BlockContentViewBuilder implements \Drupal\Core\Entity\EntityViewBuilder
- class \Drupal\Core\Entity\EntityViewBuilder extends \Drupal\Core\Entity\EntityHandlerInterface, \Drupal\Core\Entity\EntityViewBuilderInterface, \Drupal\Core\Security\TrustedCallbackInterface implements \Drupal\Core\Entity\EntityHandlerBase
Expanded class hierarchy of BlockContentViewBuilder
See also
\Drupal\block_content\Plugin\Block\BlockContentBlock
File
-
core/
modules/ block_content/ src/ BlockContentViewBuilder.php, line 18
Namespace
Drupal\block_contentView source
class BlockContentViewBuilder extends EntityViewBuilder {
/**
* {@inheritdoc}
*/
public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
return $this->viewMultiple([
$entity,
], $view_mode, $langcode)[0];
}
/**
* {@inheritdoc}
*/
public function viewMultiple(array $entities = [], $view_mode = 'full', $langcode = NULL) {
$build_list = parent::viewMultiple($entities, $view_mode, $langcode);
// Apply the buildMultiple() #pre_render callback immediately, to make
// bubbling of attributes and contextual links to the actual block work.
// @see \Drupal\block\BlockViewBuilder::buildBlock()
unset($build_list['#pre_render'][0]);
return $this->buildMultiple($build_list);
}
/**
* {@inheritdoc}
*/
protected function getBuildDefaults(EntityInterface $entity, $view_mode) {
$build = parent::getBuildDefaults($entity, $view_mode);
// The custom block will be rendered in the wrapped block template already
// and thus has no entity template itself.
unset($build['#theme']);
return $build;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.