Mercurial > hg > cmmr2012-drupal-site
diff core/modules/block_content/src/BlockContentViewBuilder.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/block_content/src/BlockContentViewBuilder.php Thu Jul 05 14:24:15 2018 +0000 @@ -0,0 +1,43 @@ +<?php + +namespace Drupal\block_content; + +use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Entity\EntityViewBuilder; + +/** + * View builder handler for custom blocks. + */ +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; + } + +}