You are here

ModerationStateTransitionStorage.php in Workbench Moderation 8

Same filename and directory in other branches
  1. 8.2 src/ModerationStateTransitionStorage.php

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;

/**
 * Define class for moderation state transitions.
 */
class ModerationStateTransitionStorage extends ConfigEntityStorage implements EntityHandlerInterface {

  /**
   * Entity type manager service.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * {@inheritdoc}
   */
  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'));
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  protected function doCreate(array $values) {

    /* @var \Drupal\workbench_moderation\ModerationStateTransitionInterface $entity */
    $entity = parent::doCreate($values);
    return $entity
      ->setModerationStateConfigPrefix($this->entityTypeManager
      ->getDefinition('moderation_state')
      ->getConfigPrefix());
  }

  /**
   * {@inheritdoc}
   */
  protected function mapFromStorageRecords(array $records) {
    $entities = parent::mapFromStorageRecords($records);
    $prefix = $this->entityTypeManager
      ->getDefinition('moderation_state')
      ->getConfigPrefix();

    /* @var \Drupal\workbench_moderation\ModerationStateTransitionInterface $entity */
    foreach ($entities as &$entity) {
      $entity
        ->setModerationStateConfigPrefix($prefix);
    }
    reset($entities);
    return $entities;
  }

}

Classes

Namesort descending Description
ModerationStateTransitionStorage Define class for moderation state transitions.