entityItems($trunk_entity); // Checking that $field is configured to reference the vocabulary of // $synonym_entity term. $is_allowed = FALSE; foreach ($this->field['settings']['allowed_values'] as $setting) { if ($synonym_entity->vocabulary_machine_name == $setting['vocabulary']) { if ($setting['parent'] == 0) { // No need to check parent property as there is no limitation on it. $is_allowed = TRUE; break; } else { foreach (taxonomy_get_parents_all($synonym_entity->tid) as $parent) { if ($parent->tid == $setting['parent']) { $is_allowed = TRUE; break(2); } } } } } if (!$is_allowed) { // Synonym term is from a vocabulary that is not expected by this field, // or under unexpected parent. return; } $items[] = array( 'tid' => $synonym_entity->tid, ); $trunk_entity->{$this->field['field_name']}[LANGUAGE_NONE] = $this->uniqueItems($items, array('tid')); } }