Skip to content

Instantly share code, notes, and snippets.

@dawehner
Created May 12, 2017 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dawehner/8b107079f941ceac0567cbd9641cddbf to your computer and use it in GitHub Desktop.
Save dawehner/8b107079f941ceac0567cbd9641cddbf to your computer and use it in GitHub Desktop.
<?php
namespace Drupal\recipes_magazin\Plugin\migrate\source;
/**
* Extends the CSV migration to make it possible to import terms.
*
* @MigrateSource(
* id = "recipe_magazin__terms"
* )
*/
class Terms extends CSV {
/**
* {@inheritdoc}
*/
protected function getIterator() {
// Iterates over the CSV rows and yields individual terms.
$csv_row_iterator = parent::getIterator();
foreach ($csv_row_iterator as $row) {
if (isset($row[$this->configuration['column']])) {
foreach (explode(',', $row[$this->configuration['column']]) as $single_term) {
yield [
$this->configuration['column'] => $single_term,
];
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment