View source
<?php
namespace Drupal\multiversion\Plugin\migrate\destination;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\Password\PasswordInterface;
use Drupal\migrate\MigrateException;
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase as CoreEntityContentBase;
use Drupal\migrate\Plugin\MigrateIdMapInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
class EntityContentBase extends CoreEntityContentBase {
protected $password;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
list($entity_type_id) = explode('__', $migration
->id());
return new static($configuration, $plugin_id, $plugin_definition, $migration, $container
->get('entity.manager')
->getStorage($entity_type_id), array_keys($container
->get('entity.manager')
->getBundleInfo($entity_type_id)), $container
->get('entity.manager'), $container
->get('plugin.manager.field.field_type'), $container
->get('password'));
}
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, PasswordInterface $password) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_manager, $field_type_manager);
$this->password = $password;
$this->storage
->resetCache();
}
public function import(Row $row, array $old_destination_id_values = []) {
$this->rollbackAction = MigrateIdMapInterface::ROLLBACK_DELETE;
$entity = $this
->getEntity($row, $old_destination_id_values);
if (!$entity) {
throw new MigrateException('Unable to get entity');
}
$ids = $this
->save($entity, $old_destination_id_values);
if ($this
->isTranslationDestination()) {
$ids[] = $entity
->language()
->getId();
}
return $ids;
}
protected function getDefinitionFromEntity($key) {
$entity_type_id = $this->storage
->getEntityTypeId();
$definitions = $this->entityManager
->getBaseFieldDefinitions($entity_type_id);
$field_definition = $definitions[$key];
return [
'type' => $field_definition
->getType(),
] + $field_definition
->getSettings();
}
}