Last updated May 16, 2013. Created by mikeryan on July 20, 2011.
Edited by arithmetric, axe312, burningdog, wesleydv. Log in to edit this page.
Some field types are more complex than others - in particular, they support a number of options controlling their behavior, or subfields providing additional data. These options or subfields can be mapped like regular fields - for example, to map the summary subfield of a text field:
<?php
$this->addFieldMapping('field_text', 'main_text');
$this->addFieldMapping('field_text:summary', 'teaser_text');
?>Most fields support a 'language' subfield - this indicates the value of the field when requested for a given language. The default is LANGUAGE_NONE ('und') - the default value when a specific language is not requested.
Text fields
Text fields (fields with machine names of 'text', 'text_long', or 'text_with_summary') have the following arguments:
- summary: A short version of the contents of the field (i.e., a "teaser" or "excerpt").
- format: The Drupal text format to apply when displaying the field (e.g., "filtered_html").
Term reference fields
Term references on Drupal 7 (fields with a machine name of 'taxonomy_term_reference') have the following arguments:
- source_type: If the argument value is 'tid', then the incoming value is assumed to be a valid term ID in the destination Drupal instance. Otherwise, it is assumed to be a term name.
- create_term: If this argument is TRUE (or any value not FALSE/0/etc.) and source_type is not 'tid', then if the name passed as the value here does not already exist in the destination vocabulary, it will be created.
- ignore_case: If this argument is TRUE, then case differences (uppercase vs. lowercase) between source data and existing term names will be ignored.
<?php
$this->addFieldMapping('field_taxonomy_reference', 'termname');
$this->addFieldMapping('field_taxonomy_reference:create_term')->defaultValue(TRUE);
?>File fields
NOTE: this applies to the original file field implementation, used in Migrate versions up through 2.3 (and still used on Drupal 6). For Migrate 2.4 on Drupal 7 (or -dev or git pulls from 4/20/12 or later), see Handling files in Drupal 7.
- source_path: Path to source file. In the case of file_blob, the desired filename to write.
- file_function: file_fast, file_move, file_copy, file_link, file_fid, or file_blob.
- file_replace: Value of $replace in that file function. Does not apply to file_fast(). Defaults to FILE_EXISTS_RENAME.
- alt: String to be used as the alt value for all file fields.
- title: String to be used as the title value for all file fields.
- description: String to be used as the description value for all file fields.
- display: String to be used as the display value for all file fields.
Comments
File fields with multiple values
For the advanced topics, nothing is presented for how to handle complex fields with multiple values. How can I pass in both the source_path and the description for a File field with multiple values?
I left some feedback also on #1279778: Improve argument passing to fields
Updated: mikeryan directed me to migrate_example WineWineMigration for an example on how to do this (#1509750: Trying to map subfields (file field description) to a multi-value file field), and I added that example to this page.
I struggled to map a simple
I struggled to map a simple taxonomy term using the source_type option. I finally found out how to do it:
$this->addFieldMapping('field_publication_type:source_type')->defaultValue('tid');
Also, this must be defined after you have mapped the field it self.
$this->addFieldMapping('field_publication_type', 'PublicationType')->xpath('PublicationType')
->callbacks(array($this, 'convertPublicationType'));
--
Peter Törnstrand, Happiness