Created
May 12, 2017 15:34
-
-
Save dawehner/8b107079f941ceac0567cbd9641cddbf to your computer and use it in GitHub Desktop.
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
<?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