Version 1
[yaffs-website] / web / modules / contrib / devel / webprofiler / src / Entity / EntityViewBuilderDecorator.php
1 <?php
2
3 namespace Drupal\webprofiler\Entity;
4
5 use Drupal\Core\Entity\EntityHandlerInterface;
6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\Core\Entity\EntityTypeInterface;
8 use Drupal\Core\Entity\EntityViewBuilderInterface;
9 use Drupal\Core\Field\FieldItemInterface;
10 use Drupal\Core\Field\FieldItemListInterface;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
12
13 /**
14  * Class EntityViewBuilderDecorator
15  */
16 class EntityViewBuilderDecorator extends EntityDecorator implements EntityHandlerInterface, EntityViewBuilderInterface {
17
18   /**
19    * @param EntityViewBuilderInterface $controller
20    */
21   public function __construct(EntityViewBuilderInterface $controller) {
22     parent::__construct($controller);
23
24     $this->entities = [];
25   }
26
27   /**
28    * {@inheritdoc}
29    */
30   public function buildComponents(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) {
31     $this->getOriginalObject()
32       ->buildComponents($build, $entities, $displays, $view_mode, $langcode);
33   }
34
35   /**
36    * {@inheritdoc}
37    */
38   public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
39     $this->entities[] = $entity;
40
41     return $this->getOriginalObject()->view($entity, $view_mode, $langcode);
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public function viewMultiple(array $entities = [], $view_mode = 'full', $langcode = NULL) {
48     $this->entities = array_merge($this->entities, $entities);
49
50     return $this->getOriginalObject()
51       ->viewMultiple($entities, $view_mode, $langcode);
52   }
53
54   /**
55    * {@inheritdoc}
56    */
57   public function resetCache(array $entities = NULL) {
58     $this->getOriginalObject()->resetCache($entities);
59   }
60
61   /**
62    * {@inheritdoc}
63    */
64   public function viewField(FieldItemListInterface $items, $display_options = []) {
65     return $this->getOriginalObject()->viewField($items, $display_options);
66   }
67
68   /**
69    * {@inheritdoc}
70    */
71   public function viewFieldItem(FieldItemInterface $item, $display_options = []) {
72     return $this->getOriginalObject()->viewFieldItem($item, $display_options);
73   }
74
75   /**
76    * {@inheritdoc}
77    */
78   public function getCacheTags() {
79     return $this->getOriginalObject()->getCacheTag();
80   }
81
82   /**
83    * {@inheritdoc}
84    */
85   public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
86     return new static(
87       $entity_type,
88       $container->get('entity.manager'),
89       $container->get('language_manager')
90     );
91   }
92 }