src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php
public function addAddress($account, AddressEntity $address, $isMain = false)
    {
        if (!$account || !$address) {
            throw new \Exception('Account and Address cannot be null');
        }
        $accountAddress = new AccountAddressEntity();
        $accountAddress->setAccount($account);
        $accountAddress->setAddress($address);
        if ($isMain) {
            $this->unsetMain($account->getAccountAddresses());
        }
        $accountAddress->setMain($isMain);
        $account->addAccountAddress($accountAddress);
        $address->addAccountAddress($accountAddress);
        $this->em->persist($accountAddress);

        return $accountAddress;
    }
public function addAddress($account, AddressEntity $address, $isMain = false)
    {
        if (!$account || !$address) {
            throw new \Exception('Account and Address cannot be null');
        }
        $accountAddress = new AccountAddressEntity();
        $accountAddress->setAccount($account);
        $accountAddress->setAddress($address);
        if ($isMain) {
            $this->unsetMain($account->getAccountAddresses());
        }
        $accountAddress->setMain($isMain);
        $account->addAccountAddress($accountAddress);
        $address->addAccountAddress($accountAddress);
        $this->em->persist($accountAddress);

        return $accountAddress;
    }
public function addAddress ( $ account , AddressEntity $ address , $ isMain = false ) { if ( ! $ account || ! $ address ) { throw new \ Exception ( 'Account and Address cannot be null' ) ; } $ accountAddress = new AccountAddressEntity ( ) ; $ accountAddress -> setAccount ( $ account ) ; $ accountAddress -> setAddress ( $ address ) ; if ( $ isMain ) { $ this -> unsetMain ( $ account -> getAccountAddresses ( ) ) ; } $ accountAddress -> setMain ( $ isMain ) ; $ account -> addAccountAddress ( $ accountAddress ) ; $ address -> addAccountAddress ( $ accountAddress ) ; $ this -> em -> persist ( $ accountAddress ) ; return $ accountAddress ; }
Adds an address to the entity.

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

@throws \Exception

@return AccountAddressEntity
Adds an address to the entity .