3 namespace Drupal\Driver\Fields\Drupal7;
6 * Taxonomy term reference field handler for Drupal 7.
8 class TaxonomyTermReferenceHandler extends AbstractHandler {
13 public function expand($values) {
15 foreach ($values as $name) {
16 $terms = taxonomy_get_term_by_name($name, $this->getVocab());
18 throw new \Exception(sprintf("No term '%s' exists.", $name));
20 $return[$this->language][] = array('tid' => array_shift($terms)->tid);
26 * Attempt to determine the vocabulary for which the field is configured.
29 * Returns a string containing the vocabulary in which the term must be
30 * found or NULL if unable to determine.
32 protected function getVocab() {
33 if (!empty($this->field_info['settings']['allowed_values'][0]['vocabulary'])) {
34 return $this->field_info['settings']['allowed_values'][0]['vocabulary'];