Created
August 7, 2013 01:45
-
-
Save vincenzodibiaggio/6170508 to your computer and use it in GitHub Desktop.
Drupal - Migration - Add term reference, included in a field collection, to an entity from CSV data
We can make this file beautiful and searchable if this error is corrected: It looks like row 3 should actually have 3 columns, instead of 1 in line 2.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"id","user","language_name" | |
1,"username","English" | |
.... | |
.... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyMigration extends MyBaseMigration { | |
public function __construct(array $arguments) { | |
parent::__construct($arguments); | |
// Description. | |
$this->description = t('Description'); | |
// Dependencies. | |
$this->dependencies = array('MyUser'); | |
// Mapping Table. | |
$this->map = new MigrateSQLMap( | |
$this->machineName, | |
array( | |
'id' => array( | |
'type' => 'int', | |
'not null' => TRUE, | |
'description' => 'Source id' | |
), | |
), | |
MigrateDestinationFieldCollection::getKeySchema() | |
); | |
$source_file = drupal_get_path('module', 'my_module') . '/data/my_data.csv'; | |
$columns = array( | |
// [..] | |
array('language_name', 'language_name'), | |
); | |
$this->source = new MigrateSourceCSV( | |
$source_file, | |
$columns, | |
array( | |
'header_rows' => 1, | |
'delimiter' => ',', | |
'enclosure' => '"' | |
) | |
); | |
$this->destination = new MigrateDestinationFieldCollection( | |
'my_field_collection_name', | |
array('host_entity_type' => 'my_entity') | |
); | |
$this->addFieldMapping('host_entity_id', 'my_entity')->sourceMigration('MyClassThatImportTheEntity'); | |
$this->addFieldMapping('term_reference_field', 'language_name'); | |
$this->addFieldMapping('term_reference_field:source_type')->defaultValue('term_name'); | |
$this->addFieldMapping('term_reference_field:create_term')->defaultValue(TRUE); | |
$this->addFieldMapping('term_reference_field:ignore_case')->defaultValue(TRUE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment