src/Sulu/Bundle/ContactBundle/Contact/AbstractContactManager.php
protected function addPhone($contact, $phoneData)
    {
        $success = true;

        $phoneType = $this->em->getRepository(
            self::$phoneTypeEntityName
        )->find($phoneData['phoneType']['id']);

        if (isset($phoneData['id'])) {
            throw new EntityIdAlreadySetException(self::$phoneEntityName, $phoneData['id']);
        } elseif (!$phoneType) {
            throw new EntityNotFoundException(self::$phoneTypeEntityName, $phoneData['phoneType']['id']);
        } else {
            $phone = new Phone();
            $phone->setPhone($phoneData['phone']);
            $phone->setPhoneType($phoneType);
            $this->em->persist($phone);
            $contact->addPhone($phone);
        }

        return $success;
    }
protected function addPhone($contact, $phoneData)
    {
        $success = true;

        $phoneType = $this->em->getRepository(
            self::$phoneTypeEntityName
        )->find($phoneData['phoneType']['id']);

        if (isset($phoneData['id'])) {
            throw new EntityIdAlreadySetException(self::$phoneEntityName, $phoneData['id']);
        } elseif (!$phoneType) {
            throw new EntityNotFoundException(self::$phoneTypeEntityName, $phoneData['phoneType']['id']);
        } else {
            $phone = new Phone();
            $phone->setPhone($phoneData['phone']);
            $phone->setPhoneType($phoneType);
            $this->em->persist($phone);
            $contact->addPhone($phone);
        }

        return $success;
    }
protected function addPhone ( $ contact , $ phoneData ) { $ success = true ; $ phoneType = $ this -> em -> getRepository ( self :: $ phoneTypeEntityName ) -> find ( $ phoneData [ 'phoneType' ] [ 'id' ] ) ; if ( isset ( $ phoneData [ 'id' ] ) ) { throw new EntityIdAlreadySetException ( self :: $ phoneEntityName , $ phoneData [ 'id' ] ) ; } elseif ( ! $ phoneType ) { throw new EntityNotFoundException ( self :: $ phoneTypeEntityName , $ phoneData [ 'phoneType' ] [ 'id' ] ) ; } else { $ phone = new Phone ( ) ; $ phone -> setPhone ( $ phoneData [ 'phone' ] ) ; $ phone -> setPhoneType ( $ phoneType ) ; $ this -> em -> persist ( $ phone ) ; $ contact -> addPhone ( $ phone ) ; } return $ success ; }
Add a new phone to the given contact and persist it with the given object manager.

@param $contact
@param array $phoneData

@throws EntityNotFoundException
@throws EntityIdAlreadySetException

@return bool True if there was no error, otherwise false
Add a new phone to the given contact and persist it with the given object manager .