View source
<?php
namespace Drupal\comment\Plugin\migrate\destination;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\MigrateException;
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
class EntityComment extends EntityContentBase {
protected $state;
protected $entityQuery;
protected $stubCommentedEntityIds;
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, StateInterface $state, QueryFactory $entity_query) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_manager, $field_type_manager);
$this->state = $state;
$this->entityQuery = $entity_query;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
$entity_type = static::getEntityTypeId($plugin_id);
return new static($configuration, $plugin_id, $plugin_definition, $migration, $container
->get('entity.manager')
->getStorage($entity_type), array_keys($container
->get('entity.manager')
->getBundleInfo($entity_type)), $container
->get('entity.manager'), $container
->get('plugin.manager.field.field_type'), $container
->get('state'), $container
->get('entity.query'));
}
public function import(Row $row, array $old_destination_id_values = array()) {
if ($row
->isStub() && ($state = $this->state
->get('comment.maintain_entity_statistics', 0))) {
$this->state
->set('comment.maintain_entity_statistics', 0);
}
$return = parent::import($row, $old_destination_id_values);
if ($row
->isStub() && $state) {
$this->state
->set('comment.maintain_entity_statistics', $state);
}
return $return;
}
protected function processStubRow(Row $row) {
parent::processStubRow($row);
$row
->setDestinationProperty('name', 'anonymous_stub');
}
}