src/TagField.php
protected function getOrCreateTag($term)
    {
        // Check if existing record can be found
        $source = $this->getSourceList();
        $titleField = $this->getTitleField();
        $record = $source
            ->filter($titleField, $term)
            ->first();
        if ($record) {
            return $record;
        }

        // Create new instance if not yet saved
        if ($this->getCanCreate()) {
            $dataClass = $source->dataClass();
            $record = Injector::inst()->create($dataClass);
            $record->{$titleField} = $term;
            $record->write();
            if ($source instanceof SS_List) {
                $source->add($record);
            }
            return $record;
        }

        return false;
    }
protected function getOrCreateTag($term)
    {
        // Check if existing record can be found
        $source = $this->getSourceList();
        $titleField = $this->getTitleField();
        $record = $source
            ->filter($titleField, $term)
            ->first();
        if ($record) {
            return $record;
        }

        // Create new instance if not yet saved
        if ($this->getCanCreate()) {
            $dataClass = $source->dataClass();
            $record = Injector::inst()->create($dataClass);
            $record->{$titleField} = $term;
            $record->write();
            if ($source instanceof SS_List) {
                $source->add($record);
            }
            return $record;
        }

        return false;
    }
protected function getOrCreateTag ( $ term ) { // Check if existing record can be found $ source = $ this -> getSourceList ( ) ; $ titleField = $ this -> getTitleField ( ) ; $ record = $ source -> filter ( $ titleField , $ term ) -> first ( ) ; if ( $ record ) { return $ record ; } // Create new instance if not yet saved if ( $ this -> getCanCreate ( ) ) { $ dataClass = $ source -> dataClass ( ) ; $ record = Injector :: inst ( ) -> create ( $ dataClass ) ; $ record -> { $ titleField } = $ term ; $ record -> write ( ) ; if ( $ source instanceof SS_List ) { $ source -> add ( $ record ) ; } return $ record ; } return false ; }
Get or create tag with the given value

@param  string $term
@return DataObject|bool
Get or create tag with the given value