Created
February 25, 2014 19:33
-
-
Save tannerjfco/9216060 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
/** | |
* eck.inc | |
* | |
* Import default content for custom entities from a CSV | |
* This Migration requires migrate_extras | |
* | |
*/ | |
class InstallECKSectionMigration extends Migration { | |
//Required Migrate Module Stuff | |
public function __construct() { | |
parent::__construct(MigrateGroup::getInstance('InstallContent')); | |
// Create map object for relationship tracking | |
$this->map = new MigrateSQLMap($this->machineName, | |
array( | |
'id' => array( | |
'type' => 'varchar', | |
'length' => 32, | |
'not null' => TRUE, | |
), | |
), | |
MigrateDestinationEntityAPI::getKeySchema('section', 'section') | |
); | |
//Create the source object of doom! | |
$this->source = new MigrateSourceCSV(drupal_get_path('module', 'pub_content') . '/import/eck_section.csv', $this->csvcolumns(), array('header_rows' => 1)); | |
//Set the destination | |
$this->destination = new MigrateDestinationEntityAPI('section', 'section'); | |
//Set the bundle | |
$this->addFieldMapping('type') | |
->defaultValue('section'); | |
$this->addFieldMapping('uid') | |
->defaultValue(1); | |
$this->addFieldMapping('id', 'id'); | |
$this->addFieldMapping('title', 'title'); | |
$this->addFieldMapping('field_section_id', 'field_section_id'); | |
$this->addFieldMapping('field_section_content', 'field_section_content'); | |
$this->addFieldMapping('field_section_image', 'field_section_image'); | |
$this->addFieldMapping('field_section_image:source_dir') | |
->defaultValue(drupal_get_path('module', 'pub_content') . '/import/files'); | |
$this->addFieldMapping('field_section_files', 'field_section_files') | |
->separator(','); | |
$this->addFieldMapping('field_section_files:display', 'field_section_files:display') | |
->separator(','); | |
$this->addFieldMapping('field_section_files:description') | |
$this->addFieldMapping('field_section_files:source_dir') | |
->defaultValue(drupal_get_path('module', 'pub_content') . '/import/files'); | |
$this->addFieldMapping('field_section_links', 'field_section_links') | |
->separator(','); | |
$this->addFieldMapping('field_section_links:title', 'field_section_links:title') | |
->separator(','); | |
} | |
function csvcolumns() { | |
// "nid", "Title", "Path", "Body" | |
$columns[0] = array('id', 'id'); | |
$columns[1] = array('title', 'title'); | |
$columns[2] = array('field_section_id', 'field_section_id'); | |
$columns[3] = array('field_section_content', 'field_section_content'); | |
$columns[4] = array('field_section_image', 'field_section_image'); | |
$columns[5] = array('field_section_files', 'field_section_files'); | |
$columns[6] = array('field_section_links', 'field_section_links'); | |
$columns[7] = array('field_section_links:title', 'field_section_links:title'); | |
return $columns; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment