src/Sulu/Bundle/ContactBundle/Controller/AccountController.php
public function deleteContactsAction($accountId, $contactId)
    {
        try {
            // Check if relation exists.
            /** @var AccountContactEntity $accountContact */
            $accountContact = $this->getDoctrine()
                ->getRepository(self::$accountContactEntityName)
                ->findByForeignIds($accountId, $contactId);

            if (!$accountContact) {
                throw new EntityNotFoundException('AccountContact', $accountId . $contactId);
            }
            $id = $accountContact->getId();

            $account = $accountContact->getAccount();

            // Remove main contact when relation with main was removed.
            if ($account->getMainContact() && strval($account->getMainContact()->getId()) === $contactId) {
                $account->setMainContact(null);
            }

            // Remove accountContact.
            $em = $this->getDoctrine()->getManager();
            $em->remove($accountContact);
            $em->flush();

            $view = $this->view($id, 200);
        } catch (EntityNotFoundException $enfe) {
            $view = $this->view($enfe->toArray(), 404);
        }

        return $this->handleView($view);
    }
public function deleteContactsAction($accountId, $contactId)
    {
        try {
            // Check if relation exists.
            /** @var AccountContactEntity $accountContact */
            $accountContact = $this->getDoctrine()
                ->getRepository(self::$accountContactEntityName)
                ->findByForeignIds($accountId, $contactId);

            if (!$accountContact) {
                throw new EntityNotFoundException('AccountContact', $accountId . $contactId);
            }
            $id = $accountContact->getId();

            $account = $accountContact->getAccount();

            // Remove main contact when relation with main was removed.
            if ($account->getMainContact() && strval($account->getMainContact()->getId()) === $contactId) {
                $account->setMainContact(null);
            }

            // Remove accountContact.
            $em = $this->getDoctrine()->getManager();
            $em->remove($accountContact);
            $em->flush();

            $view = $this->view($id, 200);
        } catch (EntityNotFoundException $enfe) {
            $view = $this->view($enfe->toArray(), 404);
        }

        return $this->handleView($view);
    }
public function deleteContactsAction ( $ accountId , $ contactId ) { try { // Check if relation exists. /** @var AccountContactEntity $accountContact */ $ accountContact = $ this -> getDoctrine ( ) -> getRepository ( self :: $ accountContactEntityName ) -> findByForeignIds ( $ accountId , $ contactId ) ; if ( ! $ accountContact ) { throw new EntityNotFoundException ( 'AccountContact' , $ accountId . $ contactId ) ; } $ id = $ accountContact -> getId ( ) ; $ account = $ accountContact -> getAccount ( ) ; // Remove main contact when relation with main was removed. if ( $ account -> getMainContact ( ) && strval ( $ account -> getMainContact ( ) -> getId ( ) ) === $ contactId ) { $ account -> setMainContact ( null ) ; } // Remove accountContact. $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> remove ( $ accountContact ) ; $ em -> flush ( ) ; $ view = $ this -> view ( $ id , 200 ) ; } catch ( EntityNotFoundException $ enfe ) { $ view = $ this -> view ( $ enfe -> toArray ( ) , 404 ) ; } return $ this -> handleView ( $ view ) ; }
Deleted account contact.

@param int $accountId
@param int $contactId

@throws \Exception

@return Response
Deleted account contact .