ModerationDeriver.php in Workbench Moderation to Content Moderation 8.2
File
src/Plugin/Deriver/ModerationDeriver.php
View source
<?php
namespace Drupal\wbm2cm\Plugin\Deriver;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\wbm2cm\Plugin\migrate\source\ContentEntityDeriver;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ModerationDeriver extends ContentEntityDeriver {
protected $entityTypes;
public function __construct(EntityTypeManagerInterface $entity_type_manager, array $entity_types) {
parent::__construct($entity_type_manager);
$this->entityTypes = $entity_types;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('entity_type.manager'), $container
->get('state')
->get('moderation_entity_types', []));
}
public function getDerivativeDefinitions($base_plugin_definition) {
foreach ($this->entityTypeManager
->getDefinitions() as $id => $entity_type) {
if ($this
->isCompatible($entity_type)) {
$derivative = $base_plugin_definition;
$derivative['id'] .= ":{$id}";
$this->derivatives[$id] = $derivative;
}
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}
protected function isCompatible(EntityTypeInterface $entity_type) {
return parent::isCompatible($entity_type) && ($entity_type
->isRevisionable() && $entity_type
->isTranslatable() && in_array($entity_type
->id(), $this->entityTypes));
}
}