Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 45
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 16
CRAP
0.00% covered (danger)
0.00%
0 / 1
InstanceStorage
0.00% covered (danger)
0.00%
0 / 45
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 16
552
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 createInstance
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 loadUnchanged
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 countFieldData
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 doDelete
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 doLoadMultiple
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
20
 doSave
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 getQueryServiceName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 has
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 purgeFieldItems
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 readFieldItemsToPurge
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 doLoadMultipleRevisionsFieldItems
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 doDeleteFieldItems
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 doDeleteRevisionFieldItems
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 doSaveFieldItems
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 doPreSave
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Drupal\display_builder;
6
7use Drupal\Core\Cache\CacheBackendInterface;
8use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface;
9use Drupal\Core\Entity\ContentEntityInterface;
10use Drupal\Core\Entity\ContentEntityStorageBase;
11use Drupal\Core\Entity\EntityFieldManagerInterface;
12use Drupal\Core\Entity\EntityInterface;
13use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
14use Drupal\Core\Entity\EntityTypeInterface;
15use Drupal\Core\Field\FieldDefinitionInterface;
16use Drupal\Core\Session\AccountInterface;
17use Drupal\Core\State\StateInterface;
18use Drupal\display_builder\Entity\Instance;
19use Symfony\Component\DependencyInjection\ContainerInterface;
20
21/**
22 * Base class for content entity storage handlers.
23 */
24class InstanceStorage extends ContentEntityStorageBase {
25
26  private const STORAGE_INDEX = 'display_builder_index';
27
28  private const STORAGE_PREFIX = 'display_builder_';
29
30  /**
31   * Current user.
32   */
33  protected AccountInterface $currentUser;
34
35  /**
36   * State API.
37   */
38  protected StateInterface $state;
39
40  /**
41   * {@inheritdoc}
42   */
43  public function __construct(
44    EntityTypeInterface $entity_type,
45    EntityFieldManagerInterface $entity_field_manager,
46    CacheBackendInterface $cache,
47    MemoryCacheInterface $memory_cache,
48    EntityTypeBundleInfoInterface $entity_type_bundle_info,
49    StateInterface $state,
50    AccountInterface $current_user,
51  ) {
52    $this->state = $state;
53    $this->currentUser = $current_user;
54    parent::__construct($entity_type, $entity_field_manager, $cache, $memory_cache, $entity_type_bundle_info);
55  }
56
57  /**
58   * {@inheritdoc}
59   */
60  public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type): self {
61    return new static(
62      $entity_type,
63      $container->get('entity_field.manager'),
64      $container->get('cache.entity'),
65      $container->get('entity.memory_cache'),
66      $container->get('entity_type.bundle.info'),
67      $container->get('state'),
68      $container->get('current_user')
69    );
70  }
71
72  /**
73   * {@inheritdoc}
74   */
75  public function loadUnchanged($id): ?EntityInterface {
76    $this->state->resetCache();
77
78    return parent::loadUnchanged($id);
79  }
80
81  /**
82   * {@inheritdoc}
83   */
84  public function countFieldData($storage_definition, $as_bool = FALSE) {
85    return $as_bool ? FALSE : 0;
86  }
87
88  /**
89   * {@inheritdoc}
90   */
91  protected function doDelete($entities): void {
92    foreach ($entities as $entity) {
93      $id = (string) $entity->id();
94      $display_builder_list = $this->state->get(self::STORAGE_INDEX, []);
95      unset($display_builder_list[$id]);
96
97      $this->state->set(self::STORAGE_INDEX, $display_builder_list);
98      $this->state->delete(self::STORAGE_PREFIX . $id);
99    }
100  }
101
102  /**
103   * {@inheritdoc}
104   */
105  protected function doLoadMultiple(?array $ids = NULL): array {
106    $entities = [];
107
108    if ($ids === NULL) {
109      $ids = \array_keys($this->state->get(self::STORAGE_INDEX, []));
110    }
111
112    foreach ($ids as $id) {
113      if ($data = $this->state->get(self::STORAGE_PREFIX . $id, NULL)) {
114        // @todo update once we manage proper revisions and translations.
115        $entities[$id] = new Instance($data, 'display_builder_instance');
116      }
117    }
118
119    return $entities;
120  }
121
122  /**
123   * {@inheritdoc}
124   */
125  protected function doSave($id, EntityInterface $entity): bool|int {
126    /** @var \Drupal\display_builder\InstanceInterface $entity */
127
128    $display_builder_list = $this->state->get(self::STORAGE_INDEX, []);
129
130    if (!isset($display_builder_list[$entity->id()])) {
131      $display_builder_list[$entity->id()] = '';
132    }
133
134    $this->state->set(self::STORAGE_INDEX, $display_builder_list);
135    $this->state->set(self::STORAGE_PREFIX . $entity->id(), $entity->toArray());
136
137    return TRUE;
138  }
139
140  /**
141   * {@inheritdoc}
142   */
143  protected function getQueryServiceName(): string {
144    return 'entity.query.null';
145  }
146
147  /**
148   * {@inheritdoc}
149   */
150  protected function has($id, EntityInterface $entity): bool {
151    if ($entity->isNew()) {
152      return FALSE;
153    }
154
155    return (bool) $this->state->get(self::STORAGE_PREFIX . $id, NULL);
156  }
157
158  /**
159   * {@inheritdoc}
160   */
161  protected function purgeFieldItems(ContentEntityInterface $entity, FieldDefinitionInterface $field_definition): void {}
162
163  /**
164   * {@inheritdoc}
165   */
166  protected function readFieldItemsToPurge(FieldDefinitionInterface $field_definition, mixed $batch_size): array {
167    return [];
168  }
169
170  /**
171   * {@inheritdoc}
172   */
173  protected function doLoadMultipleRevisionsFieldItems(mixed $revision_ids): array {
174    return [];
175  }
176
177  /**
178   * {@inheritdoc}
179   */
180  protected function doDeleteFieldItems(mixed $entities): void {}
181
182  /**
183   * {@inheritdoc}
184   */
185  protected function doDeleteRevisionFieldItems(ContentEntityInterface $revision): void {}
186
187  /**
188   * {@inheritdoc}
189   */
190  protected function doSaveFieldItems(ContentEntityInterface $entity, array $names = []): void {}
191
192  /**
193   * {@inheritdoc}
194   */
195  protected function doPreSave(EntityInterface $entity): int|string|null {
196    return $entity->id();
197  }
198
199}

Paths

Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once. Please also be aware that some paths may include implicit rather than explicit branches, e.g. an if statement always has an else as part of its logical flow even if you didn't write one.

InstanceStorage->__construct
44    EntityTypeInterface $entity_type,
45    EntityFieldManagerInterface $entity_field_manager,
46    CacheBackendInterface $cache,
47    MemoryCacheInterface $memory_cache,
48    EntityTypeBundleInfoInterface $entity_type_bundle_info,
49    StateInterface $state,
50    AccountInterface $current_user,
51  ) {
52    $this->state = $state;
53    $this->currentUser = $current_user;
54    parent::__construct($entity_type, $entity_field_manager, $cache, $memory_cache, $entity_type_bundle_info);
55  }
InstanceStorage->countFieldData
84  public function countFieldData($storage_definition, $as_bool = FALSE) {
85    return $as_bool ? FALSE : 0;
 
85    return $as_bool ? FALSE : 0;
 
85    return $as_bool ? FALSE : 0;
86  }
84  public function countFieldData($storage_definition, $as_bool = FALSE) {
85    return $as_bool ? FALSE : 0;
 
85    return $as_bool ? FALSE : 0;
 
85    return $as_bool ? FALSE : 0;
86  }
InstanceStorage->createInstance
60  public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type): self {
61    return new static(
62      $entity_type,
63      $container->get('entity_field.manager'),
64      $container->get('cache.entity'),
65      $container->get('entity.memory_cache'),
66      $container->get('entity_type.bundle.info'),
67      $container->get('state'),
68      $container->get('current_user')
69    );
70  }
InstanceStorage->doDelete
91  protected function doDelete($entities): void {
92    foreach ($entities as $entity) {
 
92    foreach ($entities as $entity) {
 
92    foreach ($entities as $entity) {
93      $id = (string) $entity->id();
 
92    foreach ($entities as $entity) {
 
92    foreach ($entities as $entity) {
93      $id = (string) $entity->id();
94      $display_builder_list = $this->state->get(self::STORAGE_INDEX, []);
95      unset($display_builder_list[$id]);
96
97      $this->state->set(self::STORAGE_INDEX, $display_builder_list);
98      $this->state->delete(self::STORAGE_PREFIX . $id);
99    }
100  }
91  protected function doDelete($entities): void {
92    foreach ($entities as $entity) {
 
92    foreach ($entities as $entity) {
 
92    foreach ($entities as $entity) {
93      $id = (string) $entity->id();
94      $display_builder_list = $this->state->get(self::STORAGE_INDEX, []);
95      unset($display_builder_list[$id]);
96
97      $this->state->set(self::STORAGE_INDEX, $display_builder_list);
98      $this->state->delete(self::STORAGE_PREFIX . $id);
99    }
100  }
91  protected function doDelete($entities): void {
92    foreach ($entities as $entity) {
 
92    foreach ($entities as $entity) {
93      $id = (string) $entity->id();
94      $display_builder_list = $this->state->get(self::STORAGE_INDEX, []);
95      unset($display_builder_list[$id]);
96
97      $this->state->set(self::STORAGE_INDEX, $display_builder_list);
98      $this->state->delete(self::STORAGE_PREFIX . $id);
99    }
100  }
InstanceStorage->doDeleteFieldItems
180  protected function doDeleteFieldItems(mixed $entities): void {}
InstanceStorage->doDeleteRevisionFieldItems
185  protected function doDeleteRevisionFieldItems(ContentEntityInterface $revision): void {}
InstanceStorage->doLoadMultiple
105  protected function doLoadMultiple(?array $ids = NULL): array {
106    $entities = [];
107
108    if ($ids === NULL) {
 
109      $ids = \array_keys($this->state->get(self::STORAGE_INDEX, []));
110    }
111
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
 
113      if ($data = $this->state->get(self::STORAGE_PREFIX . $id, NULL)) {
 
112    foreach ($ids as $id) {
113      if ($data = $this->state->get(self::STORAGE_PREFIX . $id, NULL)) {
114        // @todo update once we manage proper revisions and translations.
115        $entities[$id] = new Instance($data, 'display_builder_instance');
 
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
113      if ($data = $this->state->get(self::STORAGE_PREFIX . $id, NULL)) {
114        // @todo update once we manage proper revisions and translations.
115        $entities[$id] = new Instance($data, 'display_builder_instance');
116      }
117    }
118
119    return $entities;
120  }
105  protected function doLoadMultiple(?array $ids = NULL): array {
106    $entities = [];
107
108    if ($ids === NULL) {
 
109      $ids = \array_keys($this->state->get(self::STORAGE_INDEX, []));
110    }
111
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
 
113      if ($data = $this->state->get(self::STORAGE_PREFIX . $id, NULL)) {
 
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
113      if ($data = $this->state->get(self::STORAGE_PREFIX . $id, NULL)) {
114        // @todo update once we manage proper revisions and translations.
115        $entities[$id] = new Instance($data, 'display_builder_instance');
116      }
117    }
118
119    return $entities;
120  }
105  protected function doLoadMultiple(?array $ids = NULL): array {
106    $entities = [];
107
108    if ($ids === NULL) {
 
109      $ids = \array_keys($this->state->get(self::STORAGE_INDEX, []));
110    }
111
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
113      if ($data = $this->state->get(self::STORAGE_PREFIX . $id, NULL)) {
114        // @todo update once we manage proper revisions and translations.
115        $entities[$id] = new Instance($data, 'display_builder_instance');
116      }
117    }
118
119    return $entities;
120  }
105  protected function doLoadMultiple(?array $ids = NULL): array {
106    $entities = [];
107
108    if ($ids === NULL) {
 
109      $ids = \array_keys($this->state->get(self::STORAGE_INDEX, []));
110    }
111
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
113      if ($data = $this->state->get(self::STORAGE_PREFIX . $id, NULL)) {
114        // @todo update once we manage proper revisions and translations.
115        $entities[$id] = new Instance($data, 'display_builder_instance');
116      }
117    }
118
119    return $entities;
120  }
105  protected function doLoadMultiple(?array $ids = NULL): array {
106    $entities = [];
107
108    if ($ids === NULL) {
 
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
 
113      if ($data = $this->state->get(self::STORAGE_PREFIX . $id, NULL)) {
 
112    foreach ($ids as $id) {
113      if ($data = $this->state->get(self::STORAGE_PREFIX . $id, NULL)) {
114        // @todo update once we manage proper revisions and translations.
115        $entities[$id] = new Instance($data, 'display_builder_instance');
 
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
113      if ($data = $this->state->get(self::STORAGE_PREFIX . $id, NULL)) {
114        // @todo update once we manage proper revisions and translations.
115        $entities[$id] = new Instance($data, 'display_builder_instance');
116      }
117    }
118
119    return $entities;
120  }
105  protected function doLoadMultiple(?array $ids = NULL): array {
106    $entities = [];
107
108    if ($ids === NULL) {
 
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
 
113      if ($data = $this->state->get(self::STORAGE_PREFIX . $id, NULL)) {
 
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
113      if ($data = $this->state->get(self::STORAGE_PREFIX . $id, NULL)) {
114        // @todo update once we manage proper revisions and translations.
115        $entities[$id] = new Instance($data, 'display_builder_instance');
116      }
117    }
118
119    return $entities;
120  }
105  protected function doLoadMultiple(?array $ids = NULL): array {
106    $entities = [];
107
108    if ($ids === NULL) {
 
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
113      if ($data = $this->state->get(self::STORAGE_PREFIX . $id, NULL)) {
114        // @todo update once we manage proper revisions and translations.
115        $entities[$id] = new Instance($data, 'display_builder_instance');
116      }
117    }
118
119    return $entities;
120  }
105  protected function doLoadMultiple(?array $ids = NULL): array {
106    $entities = [];
107
108    if ($ids === NULL) {
 
112    foreach ($ids as $id) {
 
112    foreach ($ids as $id) {
113      if ($data = $this->state->get(self::STORAGE_PREFIX . $id, NULL)) {
114        // @todo update once we manage proper revisions and translations.
115        $entities[$id] = new Instance($data, 'display_builder_instance');
116      }
117    }
118
119    return $entities;
120  }
InstanceStorage->doLoadMultipleRevisionsFieldItems
173  protected function doLoadMultipleRevisionsFieldItems(mixed $revision_ids): array {
174    return [];
175  }
InstanceStorage->doPreSave
195  protected function doPreSave(EntityInterface $entity): int|string|null {
196    return $entity->id();
197  }
InstanceStorage->doSave
125  protected function doSave($id, EntityInterface $entity): bool|int {
126    /** @var \Drupal\display_builder\InstanceInterface $entity */
127
128    $display_builder_list = $this->state->get(self::STORAGE_INDEX, []);
129
130    if (!isset($display_builder_list[$entity->id()])) {
 
131      $display_builder_list[$entity->id()] = '';
132    }
133
134    $this->state->set(self::STORAGE_INDEX, $display_builder_list);
 
134    $this->state->set(self::STORAGE_INDEX, $display_builder_list);
135    $this->state->set(self::STORAGE_PREFIX . $entity->id(), $entity->toArray());
136
137    return TRUE;
138  }
125  protected function doSave($id, EntityInterface $entity): bool|int {
126    /** @var \Drupal\display_builder\InstanceInterface $entity */
127
128    $display_builder_list = $this->state->get(self::STORAGE_INDEX, []);
129
130    if (!isset($display_builder_list[$entity->id()])) {
 
134    $this->state->set(self::STORAGE_INDEX, $display_builder_list);
135    $this->state->set(self::STORAGE_PREFIX . $entity->id(), $entity->toArray());
136
137    return TRUE;
138  }
InstanceStorage->doSaveFieldItems
190  protected function doSaveFieldItems(ContentEntityInterface $entity, array $names = []): void {}
InstanceStorage->getQueryServiceName
144    return 'entity.query.null';
145  }
InstanceStorage->has
150  protected function has($id, EntityInterface $entity): bool {
151    if ($entity->isNew()) {
 
152      return FALSE;
150  protected function has($id, EntityInterface $entity): bool {
151    if ($entity->isNew()) {
 
155    return (bool) $this->state->get(self::STORAGE_PREFIX . $id, NULL);
156  }
InstanceStorage->loadUnchanged
75  public function loadUnchanged($id): ?EntityInterface {
76    $this->state->resetCache();
77
78    return parent::loadUnchanged($id);
79  }
InstanceStorage->purgeFieldItems
161  protected function purgeFieldItems(ContentEntityInterface $entity, FieldDefinitionInterface $field_definition): void {}
InstanceStorage->readFieldItemsToPurge
166  protected function readFieldItemsToPurge(FieldDefinitionInterface $field_definition, mixed $batch_size): array {
167    return [];
168  }