View source
<?php
namespace Drupal\commerce_log;
use Drupal\commerce\CommerceContentEntityStorage;
use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class LogStorage extends CommerceContentEntityStorage implements LogStorageInterface {
protected $logTemplateManager;
public function __construct(EntityTypeInterface $entity_type, Connection $database, EntityFieldManagerInterface $entity_field_manager, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityTypeManagerInterface $entity_type_manager, EventDispatcherInterface $event_dispatcher, LogTemplateManagerInterface $log_template_manager) {
parent::__construct($entity_type, $database, $entity_field_manager, $cache, $language_manager, $memory_cache, $entity_type_bundle_info, $entity_type_manager, $event_dispatcher);
$this->logTemplateManager = $log_template_manager;
}
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('database'), $container
->get('entity_field.manager'), $container
->get('cache.entity'), $container
->get('language_manager'), $container
->get('entity.memory_cache'), $container
->get('entity_type.bundle.info'), $container
->get('entity_type.manager'), $container
->get('event_dispatcher'), $container
->get('plugin.manager.commerce_log_template'));
}
public function generate(ContentEntityInterface $source, $template_id, array $params = []) {
$template_plugin = $this->logTemplateManager
->getDefinition($template_id);
$log = $this
->create([
'category_id' => $template_plugin['category'],
'template_id' => $template_id,
'source_entity_id' => $source
->id(),
'source_entity_type' => $source
->getEntityTypeId(),
'params' => $params,
]);
return $log;
}
public function loadMultipleByEntity(ContentEntityInterface $entity) {
return $this
->loadByProperties([
'source_entity_id' => $entity
->id(),
'source_entity_type' => $entity
->getEntityTypeId(),
]);
}
}