SourcePluginBase.php in Multiversion 8
File
src/Plugin/migrate/source/SourcePluginBase.php
View source
<?php
namespace Drupal\multiversion\Plugin\migrate\source;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Plugin\migrate\source\SourcePluginBase as CoreSourcePluginBase;
use Drupal\migrate\Plugin\MigrationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class SourcePluginBase extends CoreSourcePluginBase implements ContainerFactoryPluginInterface {
protected $entityManager;
protected $entityTypeId;
protected $entityIdKey;
private $entityLanguageKey;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
return new static($configuration, $plugin_id, $plugin_definition, $migration, $container
->get('entity.manager'));
}
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityManagerInterface $entity_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
$this->entityManager = $entity_manager;
list($entity_type_id) = explode('__', $migration
->id());
$entity_type = $entity_manager
->getDefinition($entity_type_id);
$this->entityTypeId = $entity_type_id;
$this->entityIdKey = $entity_type
->getKey('id');
$this->entityLanguageKey = $entity_type
->getKey('langcode');
}
public function getIds() {
$ids[$this->entityIdKey] = $this
->getDefinitionFromEntity($this->entityIdKey);
if ($this->entityLanguageKey) {
$ids[$this->entityLanguageKey] = $this
->getDefinitionFromEntity($this->entityLanguageKey);
}
return $ids;
}
protected function getDefinitionFromEntity($key) {
$definitions = $this->entityManager
->getBaseFieldDefinitions($this->entityTypeId);
$field_definition = $definitions[$key];
return [
'type' => $field_definition
->getType(),
] + $field_definition
->getSettings();
}
public function fields() {
return [];
}
public function bundleMigrationRequired() {
return FALSE;
}
public function __toString() {
return '';
}
}