NodeStorage.php in Multiversion 8
File
src/Entity/Storage/Sql/NodeStorage.php
View source
<?php
namespace Drupal\multiversion\Entity\Storage\Sql;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Extension\ModuleHandler;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\multiversion\Entity\Storage\ContentEntityStorageInterface;
use Drupal\multiversion\Entity\Storage\ContentEntityStorageTrait;
use Drupal\node\NodeStorage as CoreNodeStorage;
use Symfony\Component\DependencyInjection\ContainerInterface;
class NodeStorage extends CoreNodeStorage implements ContentEntityStorageInterface {
use ContentEntityStorageTrait {
delete as deleteEntities;
truncate as truncateEntityTables;
}
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('database'), $container
->get('entity.manager'), $container
->get('cache.entity'), $container
->get('language_manager'), $container
->get('module_handler'));
}
public function __construct(EntityTypeInterface $entity_type, Connection $database, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, ModuleHandler $module_handler) {
parent::__construct($entity_type, $database, $entity_manager, $cache, $language_manager);
$this->moduleHandler = $module_handler;
}
public function delete(array $entities) {
foreach ($entities as $entity) {
if ($this->moduleHandler
->moduleExists('comment')) {
try {
comment_entity_predelete($entity);
} catch (\Exception $e) {
}
}
if ($this->moduleHandler
->moduleExists('menu_link_content')) {
try {
menu_link_content_entity_predelete($entity);
} catch (\Exception $e) {
}
}
}
$this
->deleteEntities($entities);
}
public function truncate() {
$this
->truncateEntityTables();
$access_control_handler = $this->entityManager
->getAccessControlHandler('node');
$access_control_handler
->deleteGrants();
}
}