I am using the Migrate (v7.x-2.2) module to migrate records from an XML source into Drupal 7.9.

I've also installed the popular link field module (v7.x-dev).

So far, in my migration class, all built-in fields work well during the migration, but I have not figured out how to migrate link fields from my XML source with their title.

I have two XML source fields (xpaths):

/record/organization/name  <-- I want to migrate this into the link title
/record/organization/url   <-- I want to migrate this into the link url

I am able to get the URL to import using this line in my Migration file (had to use link v7.x-dev module, not 7.x-1.0):

   $this->addFieldMapping('field_organization', 'organization_url')->xpath('/record/organization/url');

...but I have no idea how to inject the /record/organization/name into the title argument:

   $this->addFieldMapping('field_organization', 'organization_url')->xpath('/record/organization/url')->arguments(array('title' => [WHAT GOES HERE?]);

2 Answers 2


So, the solution is to not use arguments, but instead, fix up the record using the prepare() method:

In the constructor:

//IMPORTANT - DO this source mapping without a destination mapping (NULL)
$this->addFieldMapping(NULL, 'organization_title')->xpath('/record/organization/title');

$this->addFieldMapping('field_organization', 'organization_url')->xpath('/record/organization/url');

Then, create a method named prepare():

function prepare($node, $rec) {
      $node->field_organization[LANGUAGE_NONE][0]['title'] = $rec->organization_title;

As of today (Nov 30, 2011), you must have the 7.x-dev version of the link module installed, not the "stable" 1.0 version, in order for link fields to work at all!



I found a working MigrateLinkFieldHandler here:


I uploaded the latest 'patch' from there, which is basicly a single class definition (*), to a file called 'link.inc' in my migratemodule, and added a reference to that file in my module.info there. Cleared caches et voila:

 $arguments = MigrateLinkFieldHandler::arguments(
      array('source_field' => 'url_title')
 $this->addFieldMapping('field_link', 'url')

(*) ofcourse, since its a patch, i had to remove all the ++++ and superfluous lines to get a nice working php class )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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