ModerationStateTransitionStorage.php in Workbench Moderation 8
File
src/ModerationStateTransitionStorage.php
View source
<?php
namespace Drupal\workbench_moderation;
use Drupal\Component\Uuid\UuidInterface;
use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\Entity\ConfigEntityStorage;
use Drupal\Core\Entity\EntityHandlerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ModerationStateTransitionStorage extends ConfigEntityStorage implements EntityHandlerInterface {
protected $entityTypeManager;
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('config.factory'), $container
->get('uuid'), $container
->get('language_manager'), $container
->get('entity_type.manager'), $container
->get('entity.memory_cache'));
}
public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityTypeManagerInterface $entity_type_manager, MemoryCacheInterface $memory_cache) {
parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager, $memory_cache);
$this->entityTypeManager = $entity_type_manager;
}
protected function doCreate(array $values) {
$entity = parent::doCreate($values);
return $entity
->setModerationStateConfigPrefix($this->entityTypeManager
->getDefinition('moderation_state')
->getConfigPrefix());
}
protected function mapFromStorageRecords(array $records) {
$entities = parent::mapFromStorageRecords($records);
$prefix = $this->entityTypeManager
->getDefinition('moderation_state')
->getConfigPrefix();
foreach ($entities as &$entity) {
$entity
->setModerationStateConfigPrefix($prefix);
}
reset($entities);
return $entities;
}
}