View source
<?php
namespace Drupal\comment\Plugin\migrate\destination;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\Session\AccountSwitcherInterface;
use Drupal\Core\State\StateInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
class EntityComment extends EntityContentBase {
protected $state;
protected $stubCommentedEntityIds;
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityFieldManagerInterface $entity_field_manager, FieldTypePluginManagerInterface $field_type_manager, StateInterface $state, AccountSwitcherInterface $account_switcher = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_field_manager, $field_type_manager, $account_switcher);
$this->state = $state;
}
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_type.manager')
->getStorage($entity_type), array_keys($container
->get('entity_type.bundle.info')
->getBundleInfo($entity_type)), $container
->get('entity_field.manager'), $container
->get('plugin.manager.field.field_type'), $container
->get('state'), $container
->get('account_switcher'));
}
public function import(Row $row, array $old_destination_id_values = []) {
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');
}
}