public function getTermId($title, $vocabulary_id, $language_id = null, $type = 0)
    {
        $title = trim($title);
        if ($title == '') {
            return false;
        }

        if (!is_numeric($vocabulary_id)) {
            $vocabulary_id = $this->vocabulary($vocabulary_id);
        }

        $language_id = $this->getLanguage($vocabulary_id, $language_id);

        $search = $this->searchTerm($title, $vocabulary_id, $language_id);
        if ($search !== null) {
            return $search;
        }

        // Add term
        $term = new TermContainer(['vocabulary_id' => $vocabulary_id]);

        if ($type !== 0) {
            $term->type = $type;
        }
        $term->save();

        // Add translation
        $translation = [
            'language_id' => $language_id,
            'title' => $title,
        ];
        $term->translations()->save(new TermData($translation));

        return $term->id;
    }
public function getTermId($title, $vocabulary_id, $language_id = null, $type = 0)
    {
        $title = trim($title);
        if ($title == '') {
            return false;
        }

        if (!is_numeric($vocabulary_id)) {
            $vocabulary_id = $this->vocabulary($vocabulary_id);
        }

        $language_id = $this->getLanguage($vocabulary_id, $language_id);

        $search = $this->searchTerm($title, $vocabulary_id, $language_id);
        if ($search !== null) {
            return $search;
        }

        // Add term
        $term = new TermContainer(['vocabulary_id' => $vocabulary_id]);

        if ($type !== 0) {
            $term->type = $type;
        }
        $term->save();

        // Add translation
        $translation = [
            'language_id' => $language_id,
            'title' => $title,
        ];
        $term->translations()->save(new TermData($translation));

        return $term->id;
    }
public function getTermId ( $ title , $ vocabulary_id , $ language_id = null , $ type = 0 ) { $ title = trim ( $ title ) ; if ( $ title == '' ) { return false ; } if ( ! is_numeric ( $ vocabulary_id ) ) { $ vocabulary_id = $ this -> vocabulary ( $ vocabulary_id ) ; } $ language_id = $ this -> getLanguage ( $ vocabulary_id , $ language_id ) ; $ search = $ this -> searchTerm ( $ title , $ vocabulary_id , $ language_id ) ; if ( $ search !== null ) { return $ search ; } // Add term $ term = new TermContainer ( [ 'vocabulary_id' => $ vocabulary_id ] ) ; if ( $ type !== 0 ) { $ term -> type = $ type ; } $ term -> save ( ) ; // Add translation $ translation = [ 'language_id' => $ language_id , 'title' => $ title , ] ; $ term -> translations ( ) -> save ( new TermData ( $ translation ) ) ; return $ term -> id ; }
Returns the id of a term, if it doesn't exist, creates it.

@param  string $title
@param  int $vocabulary_id
@param  int $language_id
@param  int $type
@return bool|int
Returns the id of a term if it doesn t exist creates it .