3 namespace Drupal\comment\Plugin\migrate\destination;
5 use Drupal\Core\Entity\EntityManagerInterface;
6 use Drupal\Core\Entity\EntityStorageInterface;
7 use Drupal\Core\Field\FieldTypePluginManagerInterface;
8 use Drupal\Core\State\StateInterface;
9 use Drupal\migrate\Plugin\MigrationInterface;
10 use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
11 use Drupal\migrate\Row;
12 use Symfony\Component\DependencyInjection\ContainerInterface;
15 * @MigrateDestination(
16 * id = "entity:comment"
19 class EntityComment extends EntityContentBase {
22 * The state storage object.
24 * @var \Drupal\Core\State\StateInterface
29 * An array of entity IDs for the 'commented entity' keyed by entity type.
33 protected $stubCommentedEntityIds;
36 * Builds an comment entity destination.
38 * @param array $configuration
39 * A configuration array containing information about the plugin instance.
40 * @param string $plugin_id
41 * The plugin_id for the plugin instance.
42 * @param mixed $plugin_definition
43 * The plugin implementation definition.
44 * @param \Drupal\migrate\Plugin\MigrationInterface $migration
46 * @param \Drupal\Core\Entity\EntityStorageInterface $storage
47 * The storage for this entity type.
48 * @param array $bundles
49 * The list of bundles this entity type has.
50 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
51 * The entity manager service.
52 * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
53 * The field type plugin manager service.
54 * @param \Drupal\Core\State\StateInterface $state
55 * The state storage object.
57 public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, StateInterface $state) {
58 parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_manager, $field_type_manager);
59 $this->state = $state;
65 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
66 $entity_type = static::getEntityTypeId($plugin_id);
72 $container->get('entity.manager')->getStorage($entity_type),
73 array_keys($container->get('entity.manager')->getBundleInfo($entity_type)),
74 $container->get('entity.manager'),
75 $container->get('plugin.manager.field.field_type'),
76 $container->get('state')
83 public function import(Row $row, array $old_destination_id_values = []) {
84 if ($row->isStub() && ($state = $this->state->get('comment.maintain_entity_statistics', 0))) {
85 $this->state->set('comment.maintain_entity_statistics', 0);
87 $return = parent::import($row, $old_destination_id_values);
88 if ($row->isStub() && $state) {
89 $this->state->set('comment.maintain_entity_statistics', $state);
97 protected function processStubRow(Row $row) {
98 parent::processStubRow($row);
99 // Neither uid nor name is required in itself, but it is required to set one
101 $row->setDestinationProperty('name', 'anonymous_stub');