Last active
May 12, 2019 17:13
-
-
Save DanLaufer/4d8e0e497f8fd8c0912384462adc4c84 to your computer and use it in GitHub Desktop.
Drupal 8 - Create Taxonomy terms programmatically from CSV
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 | |
use Drupal\taxonomy\Entity\Term; | |
ini_set('auto_detect_line_endings', TRUE); | |
$rows = array_map('str_getcsv', file('./scripts/media/taxonomy.csv')); | |
$header = array_shift($rows); | |
$csv = array(); | |
foreach ($rows as $row) { | |
$csv[] = array_combine($header, $row); | |
} | |
foreach($csv as $item) { | |
$create_result = Term::create([ | |
'name' => $item['name'], | |
'vid' => $item['vocabulary'], | |
])->save(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment