EntityManagerWrapper.php in Devel 8
File
webprofiler/src/Entity/EntityManagerWrapper.php
View source
<?php
namespace Drupal\webprofiler\Entity;
use Drupal\Core\Config\Entity\ConfigEntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\EntityViewBuilderInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\webprofiler\Entity\Decorators\Config\ConfigEntityStorageDecorator;
use Drupal\webprofiler\Entity\Decorators\Config\ImageStyleStorageDecorator;
use Drupal\webprofiler\Entity\Decorators\Config\RoleStorageDecorator;
use Drupal\webprofiler\Entity\Decorators\Config\ShortcutSetStorageDecorator;
use Drupal\webprofiler\Entity\Decorators\Config\VocabularyStorageDecorator;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class EntityManagerWrapper extends DefaultPluginManager implements EntityTypeManagerInterface, ContainerAwareInterface {
private $loaded;
private $rendered;
private $entityManager;
public function __construct(EntityTypeManagerInterface $entityManager) {
$this->entityManager = $entityManager;
}
public function getStorage($entity_type) {
$handler = $this
->getHandler($entity_type, 'storage');
$type = $handler instanceof ConfigEntityStorageInterface ? 'config' : 'content';
if (!isset($this->loaded[$type][$entity_type])) {
$handler = $this
->getStorageDecorator($entity_type, $handler);
$this->loaded[$type][$entity_type] = $handler;
}
else {
$handler = $this->loaded[$type][$entity_type];
}
return $handler;
}
public function getViewBuilder($entity_type) {
$handler = $this
->getHandler($entity_type, 'view_builder');
if ($handler instanceof EntityViewBuilderInterface) {
if (!isset($this->rendered[$entity_type])) {
$handler = new EntityViewBuilderDecorator($handler);
$this->rendered[$entity_type] = $handler;
}
else {
$handler = $this->rendered[$entity_type];
}
}
return $handler;
}
private function getStorageDecorator($entity_type, $handler) {
if ($handler instanceof ConfigEntityStorageInterface) {
switch ($entity_type) {
case 'taxonomy_vocabulary':
return new VocabularyStorageDecorator($handler);
break;
case 'user_role':
return new RoleStorageDecorator($handler);
break;
case 'shortcut_set':
return new ShortcutSetStorageDecorator($handler);
break;
case 'image_style':
return new ImageStyleStorageDecorator($handler);
break;
default:
return new ConfigEntityStorageDecorator($handler);
break;
}
}
return $handler;
}
public function getLoaded($type, $entity_type) {
return isset($this->loaded[$type][$entity_type]) ? $this->loaded[$type][$entity_type] : NULL;
}
public function getRendered($entity_type) {
return isset($this->rendered[$entity_type]) ? $this->rendered[$entity_type] : NULL;
}
public function useCaches($use_caches = FALSE) {
$this->entityManager
->useCaches($use_caches);
}
public function hasDefinition($plugin_id) {
return $this->entityManager
->hasDefinition($plugin_id);
}
public function getAccessControlHandler($entity_type) {
return $this->entityManager
->getAccessControlHandler($entity_type);
}
public function clearCachedDefinitions() {
$this->entityManager
->clearCachedDefinitions();
}
public function getListBuilder($entity_type) {
return $this->entityManager
->getListBuilder($entity_type);
}
public function getFormObject($entity_type, $operation) {
return $this->entityManager
->getFormObject($entity_type, $operation);
}
public function getRouteProviders($entity_type) {
return $this->entityManager
->getRouteProviders($entity_type);
}
public function hasHandler($entity_type, $handler_type) {
return $this->entityManager
->hasHandler($entity_type, $handler_type);
}
public function getHandler($entity_type, $handler_type) {
return $this->entityManager
->getHandler($entity_type, $handler_type);
}
public function createHandlerInstance($class, EntityTypeInterface $definition = NULL) {
return $this->entityManager
->createHandlerInstance($class, $definition);
}
public function getDefinition($entity_type_id, $exception_on_invalid = TRUE) {
return $this->entityManager
->getDefinition($entity_type_id, $exception_on_invalid);
}
public function getDefinitions() {
return $this->entityManager
->getDefinitions();
}
public function createInstance($plugin_id, array $configuration = []) {
return $this->entityManager
->createInstance($plugin_id, $configuration);
}
public function getInstance(array $options) {
return $this->entityManager
->getInstance($options);
}
public function setContainer(ContainerInterface $container = NULL) {
$this->entityManager
->setContainer($container);
}
}