private static function Terms::unpackParents in Hook Update Deploy Tools 7
Unpacks import ->parents and creates ->parent for importing any parents.
Parameters
object $term_import: The term object from the import file.
Throws
HudtException In the event that the parent does not exist.
1 call to Terms::unpackParents()
- Terms::importOne in src/
Terms.php - Validated Updates/Imports one term from the contents of an import file.
File
- src/
Terms.php, line 571
Class
- Terms
- Public methods for dealing with Vocabularies.
Namespace
HookUpdateDeployToolsCode
private static function unpackParents(&$term_import) {
$new_parents = array();
if (!empty($term_import->parents)) {
// We have parents to deal with.
foreach ($term_import->parents as $parent) {
// Look up the parent in this environment to get the tid.
$local_parent = self::loadByName($parent->name, $parent->vocabulary_machine_name);
if (empty($local_parent)) {
// The parent does not exist locally, log an error.
$variables = array(
'@vocab_name' => $term_import->vocabulary_machine_name,
'@term_name' => $term_import->name,
'@parent_name' => $parent->name,
);
$message = "Import of @vocab_name:@term_name failed because the parent:@parent_name does not exist.";
throw new HudtException($message, $variables, WATCHDOG_ERROR, TRUE);
}
else {
// The parent exists locally, so use its tid.
$new_parents[] = $local_parent->tid;
}
}
}
if (!empty($new_parents)) {
// Add the local parents.
$term_import->parent = $new_parents;
}
else {
// Needs to be array(0) in order to set <root> as the parent.
$term_import->parent = array(
0,
);
}
unset($term_import->parents);
}