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

        $emailType = $this->em
            ->getRepository(self::$emailTypeEntityName)
            ->find($emailData['emailType']['id']);

        if (isset($emailData['id'])) {
            throw new EntityIdAlreadySetException(self::$emailEntityName, $emailData['id']);
        } elseif (!$emailType) {
            throw new EntityNotFoundException(self::$emailTypeEntityName, $emailData['emailType']['id']);
        } else {
            $email = new Email();
            $email->setEmail($emailData['email']);
            $email->setEmailType($emailType);
            $this->em->persist($email);
            $contact->addEmail($email);
        }

        return $success;
    }
protected function addEmail($contact, $emailData)
    {
        $success = true;

        $emailType = $this->em
            ->getRepository(self::$emailTypeEntityName)
            ->find($emailData['emailType']['id']);

        if (isset($emailData['id'])) {
            throw new EntityIdAlreadySetException(self::$emailEntityName, $emailData['id']);
        } elseif (!$emailType) {
            throw new EntityNotFoundException(self::$emailTypeEntityName, $emailData['emailType']['id']);
        } else {
            $email = new Email();
            $email->setEmail($emailData['email']);
            $email->setEmailType($emailType);
            $this->em->persist($email);
            $contact->addEmail($email);
        }

        return $success;
    }
protected function addEmail ( $ contact , $ emailData ) { $ success = true ; $ emailType = $ this -> em -> getRepository ( self :: $ emailTypeEntityName ) -> find ( $ emailData [ 'emailType' ] [ 'id' ] ) ; if ( isset ( $ emailData [ 'id' ] ) ) { throw new EntityIdAlreadySetException ( self :: $ emailEntityName , $ emailData [ 'id' ] ) ; } elseif ( ! $ emailType ) { throw new EntityNotFoundException ( self :: $ emailTypeEntityName , $ emailData [ 'emailType' ] [ 'id' ] ) ; } else { $ email = new Email ( ) ; $ email -> setEmail ( $ emailData [ 'email' ] ) ; $ email -> setEmailType ( $ emailType ) ; $ this -> em -> persist ( $ email ) ; $ contact -> addEmail ( $ email ) ; } return $ success ; }
Adds a new email to the given contact and persist it with the given object manager.

@param Contact $contact
@param array $emailData

@return bool

@throws EntityNotFoundException
@throws EntityIdAlreadySetException
Adds a new email to the given contact and persist it with the given object manager .