src/Sulu/Bundle/ContactBundle/Contact/AccountManager.php
public function removeAddressRelation($account, $accountAddress)
    {
        if (!$account || !$accountAddress) {
            throw new \Exception('Account and AccountAddress cannot be null');
        }

        // Reload address to get all data (including relational data).
        /** @var AddressEntity $address */
        $address = $accountAddress->getAddress();
        $address = $this->em->getRepository('SuluContactBundle:Address')
            ->findById($address->getId());

        $isMain = $accountAddress->getMain();

        // Remove relation.
        $address->removeAccountAddress($accountAddress);
        $account->removeAccountAddress($accountAddress);

        // If was main, set a new one.
        if ($isMain) {
            $this->setMainForCollection($account->getAccountContacts());
        }

        // Delete address if it has no more relations.
        if (!$address->hasRelations()) {
            $this->em->remove($address);
        }

        $this->em->remove($accountAddress);
    }
public function removeAddressRelation($account, $accountAddress)
    {
        if (!$account || !$accountAddress) {
            throw new \Exception('Account and AccountAddress cannot be null');
        }

        // Reload address to get all data (including relational data).
        /** @var AddressEntity $address */
        $address = $accountAddress->getAddress();
        $address = $this->em->getRepository('SuluContactBundle:Address')
            ->findById($address->getId());

        $isMain = $accountAddress->getMain();

        // Remove relation.
        $address->removeAccountAddress($accountAddress);
        $account->removeAccountAddress($accountAddress);

        // If was main, set a new one.
        if ($isMain) {
            $this->setMainForCollection($account->getAccountContacts());
        }

        // Delete address if it has no more relations.
        if (!$address->hasRelations()) {
            $this->em->remove($address);
        }

        $this->em->remove($accountAddress);
    }
public function removeAddressRelation ( $ account , $ accountAddress ) { if ( ! $ account || ! $ accountAddress ) { throw new \ Exception ( 'Account and AccountAddress cannot be null' ) ; } // Reload address to get all data (including relational data). /** @var AddressEntity $address */ $ address = $ accountAddress -> getAddress ( ) ; $ address = $ this -> em -> getRepository ( 'SuluContactBundle:Address' ) -> findById ( $ address -> getId ( ) ) ; $ isMain = $ accountAddress -> getMain ( ) ; // Remove relation. $ address -> removeAccountAddress ( $ accountAddress ) ; $ account -> removeAccountAddress ( $ accountAddress ) ; // If was main, set a new one. if ( $ isMain ) { $ this -> setMainForCollection ( $ account -> getAccountContacts ( ) ) ; } // Delete address if it has no more relations. if ( ! $ address -> hasRelations ( ) ) { $ this -> em -> remove ( $ address ) ; } $ this -> em -> remove ( $ accountAddress ) ; }
Removes the address relation from a contact and also deletes the address
if it has no more relations.

@param AccountInterface $account
@param AccountAddressEntity $accountAddress

@throws \Exception

@return mixed|void
Removes the address relation from a contact and also deletes the address if it has no more relations .