/**
  * @param Account $account
  * @param AccountAddress $address
  * @return array
  * @throws BadRequestHttpException
  */
 protected function update(Account $account, AccountAddress $address)
 {
     $responseData = ['saved' => false, 'entity' => $account];
     if ($this->getRequest()->getMethod() === 'GET' && !$address->getId() && !$account->getAddresses()->count()) {
         $address->setPrimary(true);
     }
     if (!$address->getFrontendOwner()) {
         $account->addAddress($address);
     } elseif ($address->getFrontendOwner()->getId() !== $account->getId()) {
         throw new BadRequestHttpException('Address must belong to Account');
     }
     $form = $this->createForm(AccountTypedAddressType::NAME, $address);
     $handler = new AddressHandler($form, $this->getRequest(), $this->getDoctrine()->getManagerForClass($this->container->getParameter('orob2b_account.entity.account_address.class')));
     if ($handler->process($address)) {
         $this->getDoctrine()->getManager()->flush();
         $responseData['entity'] = $address;
         $responseData['saved'] = true;
     }
     $responseData['form'] = $form->createView();
     $responseData['routes'] = ['create' => 'orob2b_account_address_create', 'update' => 'orob2b_account_address_update'];
     return $responseData;
 }