3 namespace Drupal\migrate_drupal\Plugin\migrate\source;
5 use Drupal\Component\Plugin\Derivative\DeriverBase;
6 use Drupal\Core\Entity\ContentEntityTypeInterface;
7 use Drupal\Core\Entity\EntityTypeManagerInterface;
8 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
12 * Deriver for content entity source plugins.
14 class ContentEntityDeriver extends DeriverBase implements ContainerDeriverInterface {
17 * The entity type manager.
19 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
21 protected $entityTypeManager;
24 * Constructs a new ContentEntityDeriver.
26 * @param string $base_plugin_id
28 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
29 * The entity type manager.
31 public function __construct($base_plugin_id, EntityTypeManagerInterface $entityTypeManager) {
32 $this->entityTypeManager = $entityTypeManager;
38 public static function create(ContainerInterface $container, $base_plugin_id) {
41 $container->get('entity_type.manager')
48 public function getDerivativeDefinitions($base_plugin_definition) {
49 $this->derivatives = [];
50 foreach ($this->entityTypeManager->getDefinitions() as $id => $definition) {
51 if ($definition instanceof ContentEntityTypeInterface) {
52 $this->derivatives[$id] = $base_plugin_definition;
53 // Provide entity_type so the source can be used apart from a deriver.
54 $this->derivatives[$id]['entity_type'] = $id;
57 return parent::getDerivativeDefinitions($base_plugin_definition);