Sulu\Bundle\ContactBundle\Contact\AccountManager::removeAddressRelation PHP Метод

removeAddressRelation() публичный Метод

Removes the address relation from a contact and also deletes the address if it has no more relations.
public removeAddressRelation ( Sulu\Bundle\ContactBundle\Entity\AccountInterface $account, AccountAddress $accountAddress ) : mixed | void
$account Sulu\Bundle\ContactBundle\Entity\AccountInterface
$accountAddress Sulu\Bundle\ContactBundle\Entity\AccountAddress
Результат mixed | void
    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);
    }