3 namespace Drupal\webprofiler\Entity;
5 use Drupal\Core\Config\Entity\ConfigEntityStorageInterface;
6 use Drupal\Core\Entity\EntityTypeInterface;
7 use Drupal\Core\Entity\EntityTypeManagerInterface;
8 use Drupal\Core\Entity\EntityViewBuilderInterface;
9 use Drupal\Core\Plugin\DefaultPluginManager;
10 use Drupal\webprofiler\Entity\Decorators\Config\ConfigEntityStorageDecorator;
11 use Drupal\webprofiler\Entity\Decorators\Config\RoleStorageDecorator;
12 use Drupal\webprofiler\Entity\Decorators\Config\ShortcutSetStorageDecorator;
13 use Drupal\webprofiler\Entity\Decorators\Config\VocabularyStorageDecorator;
14 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
15 use Symfony\Component\DependencyInjection\ContainerInterface;
18 * Class EntityManagerWrapper
20 class EntityManagerWrapper extends DefaultPluginManager implements EntityTypeManagerInterface, ContainerAwareInterface {
33 * @var \Drupal\Core\Entity\EntityManagerInterface
35 private $entityManager;
38 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityManager
40 public function __construct(EntityTypeManagerInterface $entityManager) {
41 $this->entityManager = $entityManager;
47 public function getStorage($entity_type) {
48 /** @var ConfigEntityStorageInterface $handler */
49 $handler = $this->getHandler($entity_type, 'storage');
50 $type = ($handler instanceof ConfigEntityStorageInterface) ? 'config' : 'content';
52 if (!isset($this->loaded[$type][$entity_type])) {
53 $handler = $this->getStorageDecorator($entity_type, $handler);
54 $this->loaded[$type][$entity_type] = $handler;
57 $handler = $this->loaded[$type][$entity_type];
66 public function getViewBuilder($entity_type) {
67 /** @var EntityViewBuilderInterface $handler */
68 $handler = $this->getHandler($entity_type, 'view_builder');
70 if ($handler instanceof EntityViewBuilderInterface) {
71 if (!isset($this->rendered[$entity_type])) {
72 $handler = new EntityViewBuilderDecorator($handler);
73 $this->rendered[$entity_type] = $handler;
76 $handler = $this->rendered[$entity_type];
87 * @return \Drupal\webprofiler\Entity\EntityDecorator
89 private function getStorageDecorator($entity_type, $handler) {
90 if ($handler instanceof ConfigEntityStorageInterface) {
91 switch ($entity_type) {
92 case 'taxonomy_vocabulary':
93 return new VocabularyStorageDecorator($handler);
96 return new RoleStorageDecorator($handler);
99 return new ShortcutSetStorageDecorator($handler);
102 return new ConfigEntityStorageDecorator($handler);
111 * @param $entity_type
115 public function getLoaded($type, $entity_type) {
116 return isset($this->loaded[$type][$entity_type]) ? $this->loaded[$type][$entity_type] : NULL;
120 * @param $entity_type
124 public function getRendered( $entity_type) {
125 return isset($this->rendered[$entity_type]) ? $this->rendered[$entity_type] : NULL;
131 public function useCaches($use_caches = FALSE) {
132 $this->entityManager->useCaches($use_caches);
138 public function hasDefinition($plugin_id) {
139 return $this->entityManager->hasDefinition($plugin_id);
145 public function getAccessControlHandler($entity_type) {
146 return $this->entityManager->getAccessControlHandler($entity_type);
152 public function clearCachedDefinitions() {
153 $this->entityManager->clearCachedDefinitions();
159 public function getListBuilder($entity_type) {
160 return $this->entityManager->getListBuilder($entity_type);
166 public function getFormObject($entity_type, $operation) {
167 return $this->entityManager->getFormObject($entity_type, $operation);
173 public function getRouteProviders($entity_type) {
174 return $this->entityManager->getRouteProviders($entity_type);
180 public function hasHandler($entity_type, $handler_type) {
181 return $this->entityManager->hasHandler($entity_type, $handler_type);
187 public function getHandler($entity_type, $handler_type) {
188 return $this->entityManager->getHandler($entity_type, $handler_type);
194 public function createHandlerInstance(
196 EntityTypeInterface $definition = NULL
198 return $this->entityManager->createHandlerInstance($class, $definition);
204 public function getDefinition($entity_type_id, $exception_on_invalid = TRUE) {
205 return $this->entityManager->getDefinition(
207 $exception_on_invalid
214 public function getDefinitions() {
215 return $this->entityManager->getDefinitions();
221 public function createInstance($plugin_id, array $configuration = []) {
222 return $this->entityManager->createInstance($plugin_id, $configuration);
228 public function getInstance(array $options) {
229 return $this->entityManager->getInstance($options);
235 public function setContainer(ContainerInterface $container = NULL) {
236 $this->entityManager->setContainer($container);