Skip to content

Instantly share code, notes, and snippets.

@lkacenja
Last active November 18, 2016 21:04
Show Gist options
  • Save lkacenja/985dc34fbb0aea51a90d43d33a482f5f to your computer and use it in GitHub Desktop.
Save lkacenja/985dc34fbb0aea51a90d43d33a482f5f to your computer and use it in GitHub Desktop.
Load Colorado Taxonomy Terms Into a Drupal 8 Vocabulary
<?php
use Drupal\taxonomy\Entity\Term;
function county_alphabetize($a, $b) {
return $a->properties->NAMELSAD > $b->properties->NAMELSAD;
}
$county = file_get_contents('https://raw.githubusercontent.com/kthotav/TopoJSON-Maps/master/usa/usa-states/colorado/colorado-counties.json');
$json = json_decode($county);
$counties = $json->objects->{'colorado-counties'}->geometries;
usort($counties, 'county_alphabetize');
foreach ($counties AS $county) {
$term = Term::create([
'name' => $county->properties->NAMELSAD,
'vid' => 'network_county',
])->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment