Mercurial > hg > cmmr2012-drupal-site
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\block_content; | |
4 | |
5 use Drupal\Core\Entity\EntityInterface; | |
6 use Drupal\Core\Entity\EntityViewBuilder; | |
7 | |
8 /** | |
9 * View builder handler for custom blocks. | |
10 */ | |
11 class BlockContentViewBuilder extends EntityViewBuilder { | |
12 | |
13 /** | |
14 * {@inheritdoc} | |
15 */ | |
16 public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) { | |
17 return $this->viewMultiple([$entity], $view_mode, $langcode)[0]; | |
18 } | |
19 | |
20 /** | |
21 * {@inheritdoc} | |
22 */ | |
23 public function viewMultiple(array $entities = [], $view_mode = 'full', $langcode = NULL) { | |
24 $build_list = parent::viewMultiple($entities, $view_mode, $langcode); | |
25 // Apply the buildMultiple() #pre_render callback immediately, to make | |
26 // bubbling of attributes and contextual links to the actual block work. | |
27 // @see \Drupal\block\BlockViewBuilder::buildBlock() | |
28 unset($build_list['#pre_render'][0]); | |
29 return $this->buildMultiple($build_list); | |
30 } | |
31 | |
32 /** | |
33 * {@inheritdoc} | |
34 */ | |
35 protected function getBuildDefaults(EntityInterface $entity, $view_mode) { | |
36 $build = parent::getBuildDefaults($entity, $view_mode); | |
37 // The custom block will be rendered in the wrapped block template already | |
38 // and thus has no entity template itself. | |
39 unset($build['#theme']); | |
40 return $build; | |
41 } | |
42 | |
43 } |