Last active
November 18, 2016 21:04
-
-
Save lkacenja/985dc34fbb0aea51a90d43d33a482f5f to your computer and use it in GitHub Desktop.
Load Colorado Taxonomy Terms Into a Drupal 8 Vocabulary
This file contains hidden or 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; | |
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