Skip to content
This repository has been archived by the owner on May 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #17 from Ymbra/csv-options
Browse files Browse the repository at this point in the history
Added feature to specify csv options in config files.
  • Loading branch information
rodrigoaguilera committed Dec 17, 2015
2 parents 9e7ec6a + 33354ff commit 236e791
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion includes/migrate_default_content.migrate.base.inc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ abstract class defaultBaseMigration extends Migration {
// Rebuild the csv columns array.
$this->csvColumns = array_merge($csv_cols, $this->csvColumns);

return new MigrateSourceCSV($this->arguments['source_path'] . '/' . $this->arguments['source_file'], $this->csvColumns, array('header_rows' => 1));
// Merge default options with other specified in config files.
$options = array('header_rows' => 1);
if ($this->migrationData['options']) {
$options = array_merge($options, $this->migrationData['options'][0]);
}
return new MigrateSourceCSV($this->arguments['source_path'] . '/' . $this->arguments['source_file'], $this->csvColumns, $options);

}

protected function addDefaultMappings() {
Expand Down
7 changes: 6 additions & 1 deletion includes/migrate_default_content.migrate.menu.inc
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,16 @@ class defaultMenu extends defaultBaseMigration {

/**
* Implements MigrateDestination::prepare().
* Adds default weight for menu item if there isn't any.
* Adds default weight for menu item if there isn't any and decode JSON
* options.
*/
public function prepareRow($row) {
if (empty($row->weight)) {
$row->weight = 0;
}
if (!empty($row->options)) {
$options = drupal_json_decode($row->options);
$row->options = $options;
}
}
}

0 comments on commit 236e791

Please sign in to comment.