Backup of db before drupal security update
[yaffs-website] / web / core / modules / block_content / src / BlockContentViewBuilder.php
1 <?php
2
3 namespace Drupal\block_content;
4
5 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\Core\Entity\EntityViewBuilder;
8
9 /**
10  * View builder handler for custom blocks.
11  */
12 class BlockContentViewBuilder extends EntityViewBuilder {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
18     return $this->viewMultiple([$entity], $view_mode, $langcode)[0];
19   }
20
21   /**
22    * {@inheritdoc}
23    */
24   public function viewMultiple(array $entities = [], $view_mode = 'full', $langcode = NULL) {
25     $build_list = parent::viewMultiple($entities, $view_mode, $langcode);
26     // Apply the buildMultiple() #pre_render callback immediately, to make
27     // bubbling of attributes and contextual links to the actual block work.
28     // @see \Drupal\block\BlockViewBuilder::buildBlock()
29     unset($build_list['#pre_render'][0]);
30     return $this->buildMultiple($build_list);
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   protected function getBuildDefaults(EntityInterface $entity, $view_mode) {
37     $build = parent::getBuildDefaults($entity, $view_mode);
38     // The custom block will be rendered in the wrapped block template already
39     // and thus has no entity template itself.
40     unset($build['#theme']);
41     return $build;
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
48     parent::alterBuild($build, $entity, $display, $view_mode);
49     // Add contextual links for this custom block.
50     if (!$entity->isNew()) {
51       $build['#contextual_links']['block_content'] = [
52         'route_parameters' => ['block_content' => $entity->id()],
53         'metadata' => ['changed' => $entity->getChangedTime()],
54       ];
55     }
56   }
57
58 }