Security update for permissions_by_term
[yaffs-website] / vendor / drupal / drupal-driver / src / Drupal / Driver / Fields / Drupal7 / TaxonomyTermReferenceHandler.php
1 <?php
2
3 namespace Drupal\Driver\Fields\Drupal7;
4
5 /**
6  * Taxonomy term reference field handler for Drupal 7.
7  */
8 class TaxonomyTermReferenceHandler extends AbstractHandler {
9
10   /**
11    * {@inheritdoc}
12    */
13   public function expand($values) {
14     $return = array();
15     foreach ($values as $name) {
16       $terms = taxonomy_get_term_by_name($name, $this->getVocab());
17       if (!$terms) {
18         throw new \Exception(sprintf("No term '%s' exists.", $name));
19       }
20       $return[$this->language][] = array('tid' => array_shift($terms)->tid);
21     }
22     return $return;
23   }
24
25   /**
26    * Attempt to determine the vocabulary for which the field is configured.
27    *
28    * @return mixed
29    *   Returns a string containing the vocabulary in which the term must be
30    *   found or NULL if unable to determine.
31    */
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'];
35     }
36   }
37
38 }