diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index d5d302d..f544c7f 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -542,7 +542,7 @@ public function getFieldMap() { else { // Rebuild the definitions and put it into the cache. foreach ($this->getDefinitions() as $entity_type_id => $entity_type) { - if ($entity_type instanceof ContentEntityTypeInterface) { + if ($entity_type->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface')) { foreach ($this->getBundleInfo($entity_type_id) as $bundle => $bundle_info) { foreach ($this->getFieldDefinitions($entity_type_id, $bundle) as $field_name => $field_definition) { $this->fieldMap[$entity_type_id][$field_name]['type'] = $field_definition->getType(); diff --git a/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/EntityComment.php b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/EntityComment.php index 94ad394..dd64262 100644 --- a/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/EntityComment.php +++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/EntityComment.php @@ -7,6 +7,7 @@ namespace Drupal\migrate\Plugin\migrate\destination; +use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\State\StateInterface; use Drupal\field\FieldInfo; @@ -51,7 +52,7 @@ class EntityComment extends EntityContentBase { * @param \Drupal\Core\State\StateInterface $state * The state storage object. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, MigratePluginManager $plugin_manager, FieldInfo $entity_manager, StateInterface $state) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, MigratePluginManager $plugin_manager, EntityManagerInterface $entity_manager, StateInterface $state) { parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $plugin_manager, $entity_manager); $this->state = $state; } diff --git a/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/EntityContentBase.php b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/EntityContentBase.php index f73bf10..ba1dd46 100644 --- a/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/EntityContentBase.php +++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/EntityContentBase.php @@ -82,14 +82,19 @@ public function import(Row $row, array $old_destination_id_values = array()) { else { $bundle = $this->storage->getEntityTypeId(); } - $field_definitions = $this->entityManager->getFieldDefinitions($this->storage->getEntityTypeId(), $bundle); - foreach ($field_definitions as $field_name => $field_definition) { - $field_type = $field_definition->getType(); - if ($this->migrateEntityFieldPluginManager->getDefinition($field_type)) { - $destination_value = $this->migrateEntityFieldPluginManager->createInstance($field_type)->import($field_definition, $row->getDestinationProperty($field_name)); - // @TODO: check for NULL return? Add an unset to $row? Maybe needed in - // exception handling? Propagate exception? - $row->setDestinationProperty($field_name, $destination_value); + // Some migrations save additional data of an existing entity and only + // provide the reference to the entity, in those cases, we can not run the + // processing below. Migrations that need that need to provide the bundle. + if ($bundle) { + $field_definitions = $this->entityManager->getFieldDefinitions($this->storage->getEntityTypeId(), $bundle); + foreach ($field_definitions as $field_name => $field_definition) { + $field_type = $field_definition->getType(); + if ($this->migrateEntityFieldPluginManager->getDefinition($field_type)) { + $destination_value = $this->migrateEntityFieldPluginManager->createInstance($field_type)->import($field_definition, $row->getDestinationProperty($field_name)); + // @TODO: check for NULL return? Add an unset to $row? Maybe needed in + // exception handling? Propagate exception? + $row->setDestinationProperty($field_name, $destination_value); + } } } $entity = $this->getEntity($row, $old_destination_id_values); diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_term_node_revision.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_term_node_revision.yml index a9d1f20..704053d 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_term_node_revision.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_term_node_revision.yml @@ -9,6 +9,7 @@ source: process: vid: vid + type: type # The actual field name is dynamic and will be added by the load plugin. destination: diff --git a/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload.yml b/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload.yml index b831add..977f7f7 100644 --- a/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload.yml +++ b/core/modules/migrate_drupal/config/install/migrate.migration.d6_upload.yml @@ -6,6 +6,7 @@ source: process: nid: nid vid: vid + type: type upload: plugin: iterator source: upload diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/Upload.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/Upload.php index 8fed280..37abe9e 100644 --- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/Upload.php +++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Plugin/migrate/source/d6/Upload.php @@ -33,6 +33,7 @@ public function query() { ->distinct() ->fields('u', array('nid', 'vid')); $query->innerJoin('node', 'n', static::JOIN); + $query->addField('n', 'type'); return $query; } @@ -56,6 +57,7 @@ public function fields() { 'fid' => $this->t('The file Id.'), 'nid' => $this->t('The node Id.'), 'vid' => $this->t('The version Id.'), + 'type' => $this->t('The node type'), 'description' => $this->t('The file description.'), 'list' => $this->t('Whether the list should be visible on the node page.'), 'weight' => $this->t('The file weight.'), diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php index ca1b489..bcbd823 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -976,6 +976,10 @@ public function testGetFieldMap() { $entity_type->expects($this->any()) ->method('getKeys') ->will($this->returnValue(array())); + $entity_type->expects($this->any()) + ->method('isSubclassOf') + ->with('\Drupal\Core\Entity\ContentEntityInterface') + ->will($this->returnValue(TRUE)); // Set up the module handler to return two bundles for the fieldable entity // type. @@ -1043,6 +1047,11 @@ public function testGetFieldMap() { // Set up a non-content entity type. $non_content_entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface'); + $entity_type->expects($this->any()) + ->method('isSubclassOf') + ->with('\Drupal\Core\Entity\ContentEntityInterface') + ->will($this->returnValue(FALSE)); + $this->setUpEntityManager(array( 'test_entity_type' => $entity_type, 'non_fieldable' => $non_content_entity_type,