/**
  * Whether the provided value is a term object.
  *
  * @param $value
  * @param $vocabulary
  *
  * @return bool|object
  */
 private static function isTermObject($value, $vocabulary)
 {
     if ($termObject = TaxonomyTerm::termExistsForTid($value, $vocabulary)) {
         // $values follows acceptable format (a).
         return $termObject;
     } elseif ($termObject = TaxonomyTerm::termExistsForName($value, $vocabulary)) {
         // $values follows acceptable format (b).
         return $termObject;
     } elseif (is_object($value)) {
         $parent_class = get_parent_class($value);
         if ($parent_class == "RedTest\\core\\entities\\TaxonomyTerm") {
             // $values follows acceptable format (i).
             return $value;
         } elseif (property_exists($value, 'tid') && ($termObject = TaxonomyTerm::termExistsForTid($value->tid, $vocabulary))) {
             // $values follows acceptable format (f).
             return $termObject;
         } elseif (property_exists($value, 'name') && ($termObject = TaxonomyTerm::termExistsForTid($value->tid, property_exists($value, 'vocabulary') ? $value->vocabulary : $vocabulary))) {
             // $values follows acceptable format (g).
             return $termObject;
         }
     } elseif (is_array($value)) {
         if (array_key_exists('tid', $value) && ($termObject = TaxonomyTerm::termExistsForTid($value['tid'], $vocabulary))) {
             // $values follows acceptable format (c).
             return $termObject;
         } elseif (array_key_exists('name', $value) && ($termObject = TaxonomyTerm::termExistsForName($value['name'], array_key_exists('vocabulary', $value) ? $value['vocabulary'] : $vocabulary))) {
             // $values follows acceptable format (d).
             return $termObject;
         }
     }
 }
Пример #2
0
 public static function createTermObjectsFromNames($names, $vocabulary = NULL, $false_on_invalid = TRUE)
 {
     $termObjects = array();
     foreach ($names as $name) {
         if ($termObject = TaxonomyTerm::termExistsForName($name, $vocabulary)) {
             $termObjects[] = $termObject;
         } elseif (!$false_on_invalid) {
             $termObjects[] = $name;
         } else {
             $termObjects[] = FALSE;
         }
     }
     return $termObjects;
 }