Right now, if you need to get the parents of a taxonomy term, you would do taxonomy_term_load(), taxonomy_get_tree(), etc. This is fine for modules that can call the Drupal API directly.

The problem comes in for modules, such as REST web service modules, which are built on top of the Entity API. These modules generally load entities using entity_load() and manipulate field vales using entity_metadata_wrapper(). In the case of taxonomy terms, this unable to get or set any information about term hierarchy, which is needed in many use-cases.

Every module built on top of the Entity API can create special cases to call the taxonomy API directly, but it might be better for Entity API to abstract this away, so you could call

$test = entity_load('taxonomy_term', $tid);
$wrapper = entity_metadata_wrapper('taxonomy_term', $test);

$parents = wrapper->parents;

Comments

micromegas’s picture

It turns out that this is already part of the Entity API.

$terms = entity_load('taxonomy_term', array($tid));
$wrapper = entity_metadata_wrapper('taxonomy_term', $terms[$tid]);
foreach ($wrapper->parent->value() as $parent) {
  $tid = $parent->tid;
  print_r($tid);
}
micromegas’s picture

Category: Feature request » Support request
Status: Active » Closed (fixed)