2ea321d7690b2e8f4ce12fc8eddaecfbab873355
[yaffs-website] / web / core / modules / block_content / src / BlockContentViewBuilder.php
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 }