public function reverseTransform($value)
    {
        if (empty($value)) {
            return null;
        }

        // Add a potential new tag entry
        $tagPrefixLength = strlen($this->newTagPrefix);
        $cleanValue = substr($value, $tagPrefixLength);
        $valuePrefix = substr($value, 0, $tagPrefixLength);
        if ($valuePrefix == $this->newTagPrefix) {
            // In that case, we have a new entry
            $entity = new $this->className;
            $this->accessor->setValue($entity, $this->textProperty, $cleanValue);
        } else {
            // We do not search for a new entry, as it does not exist yet, by definition
            try {
                $entity = $this->em->createQueryBuilder()
                    ->select('entity')
                    ->from($this->className, 'entity')
                    ->where('entity.'.$this->primaryKey.' = :id')
                    ->setParameter('id', $value)
                    ->getQuery()
                    ->getSingleResult();
            }
            catch (\Exception $ex) {
                // this will happen if the form submits invalid data
                throw new TransformationFailedException(sprintf('The choice "%s" does not exist or is not unique', $value));
            }
        }

        if (!$entity) {
            return null;
        }

        return $entity;
    }
public function reverseTransform($value)
    {
        if (empty($value)) {
            return null;
        }

        // Add a potential new tag entry
        $tagPrefixLength = strlen($this->newTagPrefix);
        $cleanValue = substr($value, $tagPrefixLength);
        $valuePrefix = substr($value, 0, $tagPrefixLength);
        if ($valuePrefix == $this->newTagPrefix) {
            // In that case, we have a new entry
            $entity = new $this->className;
            $this->accessor->setValue($entity, $this->textProperty, $cleanValue);
        } else {
            // We do not search for a new entry, as it does not exist yet, by definition
            try {
                $entity = $this->em->createQueryBuilder()
                    ->select('entity')
                    ->from($this->className, 'entity')
                    ->where('entity.'.$this->primaryKey.' = :id')
                    ->setParameter('id', $value)
                    ->getQuery()
                    ->getSingleResult();
            }
            catch (\Exception $ex) {
                // this will happen if the form submits invalid data
                throw new TransformationFailedException(sprintf('The choice "%s" does not exist or is not unique', $value));
            }
        }

        if (!$entity) {
            return null;
        }

        return $entity;
    }
public function reverseTransform ( $ value ) { if ( empty ( $ value ) ) { return null ; } // Add a potential new tag entry $ tagPrefixLength = strlen ( $ this -> newTagPrefix ) ; $ cleanValue = substr ( $ value , $ tagPrefixLength ) ; $ valuePrefix = substr ( $ value , 0 , $ tagPrefixLength ) ; if ( $ valuePrefix == $ this -> newTagPrefix ) { // In that case, we have a new entry $ entity = new $ this -> className ; $ this -> accessor -> setValue ( $ entity , $ this -> textProperty , $ cleanValue ) ; } else { // We do not search for a new entry, as it does not exist yet, by definition try { $ entity = $ this -> em -> createQueryBuilder ( ) -> select ( 'entity' ) -> from ( $ this -> className , 'entity' ) -> where ( 'entity.' . $ this -> primaryKey . ' = :id' ) -> setParameter ( 'id' , $ value ) -> getQuery ( ) -> getSingleResult ( ) ; } catch ( \ Exception $ ex ) { // this will happen if the form submits invalid data throw new TransformationFailedException ( sprintf ( 'The choice "%s" does not exist or is not unique' , $ value ) ) ; } } if ( ! $ entity ) { return null ; } return $ entity ; }
Transform single id value to an entity

@param string $value
@return mixed|null|object
Transform single id value to an entity