0

My requirement is to migrate content nodes in xml format to drupal 7 content type fields.The xml contains a node which has to be field collection in drupal.I know how to migrate field which are enity references and term references.But i am new to field collection migration.I am using drupal migrate contrib module for migration. The field collection node in my xml file.

<myphotos_grid grid="true"><![CDATA[<rows>
  <row rowID="1">
    <rowAttribute>
      <theName>photo-name</theName>
      <value>photname1</value>
    </rowAttribute>
    <rowAttribute>
      <theName>photo-credit</theName>
      <value>my credit</value>
    </rowAttribute>
    <rowAttribute>
      <theName>photo</theName>
      <value>
      <attachment id="1009343343"/>
      </value>
    </rowAttribute>
  </row>
  <row rowID="2">
    <rowAttribute>
      <theName>photo-name</theName>
      <value/>
    </rowAttribute>
    <rowAttribute>
      <theName>photo-credit</theName>
      <value/>
    </rowAttribute>
    <rowAttribute>
      <theName>photo</theName>
      <value>
      <attachment id="4432434344"/>
      </value>
    </rowAttribute>
  </row>
</rows>]]></myphotos_grid>

I am writing a base class for my content types migration by extending XMLMigration class and it defines the migration source files and destination.Also i am writing corresponding classes for each content type which defines the field mapping by extending base class.

Above xml grid node in xml which has to be migrated to to field collection in my content type X in drupal 7 site.

My queries

Whether i need to write a seperate class for field collection extending my custom content type X migration class or adding the field mappings for field collection in the custom content type X migration class? Whcih is the best standard to migrate field collection in drupal?

I am new to this field collection migration,please help,Also very sorry for my english.

0

I think you're on the right track. If I'm understanding your question, you won't need to add an extra class. Instead, you'll want to use your existing Migration class's complete() method, which is called after the node has been created. Within complete(), you can then use entity_create to create your field collection and entity_metadata_wrapper around your newly migrated node to set a reference to your field collection entity.

In psuedocode,

public function complete($entity, stdClass $row) {
  fc_entity = entity_create(...) 
  $ewrapper = entity_metadata_wrapper('node', $entity);
  $ewrapper->fc_ref_field->set( $fc_entity->nid );
  $ewrapper->save();
}   

Or something thereabouts. When in doubt, "whatever works" is the correct standard for migration code. Hope that helps get you started!

  • Hi @Complex Views,thanks very much for the response, I have written my custom field collection migration class which extends my base class.I tried to migrate the fields,but only one row is getting migrated in the field collection.I am confused with how the mapping is happening in xml to field collection? – Vishnu Jul 9 '14 at 15:28
0

Did you check Migrate Field Collections

Field collections are separate entities, which are linked to host entities. That is why we have to create separate migration classes for every field collection field.

-2

i have found one method to migrate field collection.It is similar to your solution.

Please read my blog http://fieldcollectionmigration7.blogspot.in/

  • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – mpdonadio Nov 17 '14 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.