annotate core/modules/block_content/src/BlockContentViewBuilder.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 1fec387a4317
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\block_content;
Chris@0 4
Chris@0 5 use Drupal\Core\Entity\EntityInterface;
Chris@0 6 use Drupal\Core\Entity\EntityViewBuilder;
Chris@0 7
Chris@0 8 /**
Chris@0 9 * View builder handler for custom blocks.
Chris@0 10 */
Chris@0 11 class BlockContentViewBuilder extends EntityViewBuilder {
Chris@0 12
Chris@0 13 /**
Chris@0 14 * {@inheritdoc}
Chris@0 15 */
Chris@0 16 public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
Chris@0 17 return $this->viewMultiple([$entity], $view_mode, $langcode)[0];
Chris@0 18 }
Chris@0 19
Chris@0 20 /**
Chris@0 21 * {@inheritdoc}
Chris@0 22 */
Chris@0 23 public function viewMultiple(array $entities = [], $view_mode = 'full', $langcode = NULL) {
Chris@0 24 $build_list = parent::viewMultiple($entities, $view_mode, $langcode);
Chris@0 25 // Apply the buildMultiple() #pre_render callback immediately, to make
Chris@0 26 // bubbling of attributes and contextual links to the actual block work.
Chris@0 27 // @see \Drupal\block\BlockViewBuilder::buildBlock()
Chris@0 28 unset($build_list['#pre_render'][0]);
Chris@0 29 return $this->buildMultiple($build_list);
Chris@0 30 }
Chris@0 31
Chris@0 32 /**
Chris@0 33 * {@inheritdoc}
Chris@0 34 */
Chris@0 35 protected function getBuildDefaults(EntityInterface $entity, $view_mode) {
Chris@0 36 $build = parent::getBuildDefaults($entity, $view_mode);
Chris@0 37 // The custom block will be rendered in the wrapped block template already
Chris@0 38 // and thus has no entity template itself.
Chris@0 39 unset($build['#theme']);
Chris@0 40 return $build;
Chris@0 41 }
Chris@0 42
Chris@0 43 }