src/Sulu/Bundle/ContactBundle/Contact/ContactManager.php
public function addAddress($contact, Address $address, $isMain)
    {
        if (!$contact || !$address) {
            throw new \Exception('Contact and Address cannot be null');
        }
        $contactAddress = new ContactAddress();
        $contactAddress->setContact($contact);
        $contactAddress->setAddress($address);
        if ($isMain) {
            $this->unsetMain($contact->getContactAddresses());
        }
        $contactAddress->setMain($isMain);
        $this->em->persist($contactAddress);

        $contact->addContactAddress($contactAddress);

        return $contactAddress;
    }
public function addAddress($contact, Address $address, $isMain)
    {
        if (!$contact || !$address) {
            throw new \Exception('Contact and Address cannot be null');
        }
        $contactAddress = new ContactAddress();
        $contactAddress->setContact($contact);
        $contactAddress->setAddress($address);
        if ($isMain) {
            $this->unsetMain($contact->getContactAddresses());
        }
        $contactAddress->setMain($isMain);
        $this->em->persist($contactAddress);

        $contact->addContactAddress($contactAddress);

        return $contactAddress;
    }
public function addAddress ( $ contact , Address $ address , $ isMain ) { if ( ! $ contact || ! $ address ) { throw new \ Exception ( 'Contact and Address cannot be null' ) ; } $ contactAddress = new ContactAddress ( ) ; $ contactAddress -> setContact ( $ contact ) ; $ contactAddress -> setAddress ( $ address ) ; if ( $ isMain ) { $ this -> unsetMain ( $ contact -> getContactAddresses ( ) ) ; } $ contactAddress -> setMain ( $ isMain ) ; $ this -> em -> persist ( $ contactAddress ) ; $ contact -> addContactAddress ( $ contactAddress ) ; return $ contactAddress ; }
adds an address to the entity.

@param Contact $contact The entity to add the address to
@param Address $address The address to be added
@param bool $isMain Defines if the address is the main Address of the contact

@return ContactAddress

@throws \Exception
adds an address to the entity .