25 June 2018

You can use migrate to import field collections. It has full support. You just need to define the host entity, where you have defined the field collection.

Source code viewer
  1. class MyMigration extends Migration {
  2.  
  3. public function __construct() {
  4. parent::__construct();
  5.  
  6. // ...
  7.  
  8. // Define the destination as field collection, add the field name on the host entity and define host entity type.
  9. $this->destination = new MigrateDestinationFieldCollection('field_my_field_collection_field', array('host_entity_type' => 'taxonomy_term'));
  10.  
  11. $this->map = new MigrateSQLMap($this->machineName,
  12. 'id' => array(
  13. 'type' => 'varchar',
  14. 'length' => 255,
  15. 'not null' => TRUE,
  16. ),
  17. ),
  18. MigrateDestinationFieldCollection::getKeySchema()
  19. );
  20.  
  21. $this->addFieldMapping('host_entity_id', 'host_entity_id_field_from_source');
  22.  
  23. // ...
  24.  
  25. }
  26.  
  27. }
  28.  
Programming Language: PHP