/**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $type = $options['addressType'];
     $order = $options['order'];
     $isManualEditGranted = $this->orderAddressSecurityProvider->isManualEditGranted($type);
     $addresses = $this->orderAddressManager->getGroupedAddresses($order, $type);
     $accountAddressOptions = ['label' => false, 'required' => false, 'mapped' => false, 'choices' => $this->getChoices($addresses), 'configs' => ['placeholder' => 'orob2b.order.form.address.choose'], 'attr' => ['data-addresses' => json_encode($this->getPlainData($addresses)), 'data-default' => $this->getDefaultAddressKey($order, $type, $addresses)]];
     if ($isManualEditGranted) {
         $accountAddressOptions['choices'] = array_merge($accountAddressOptions['choices'], ['orob2b.order.form.address.manual']);
         $accountAddressOptions['configs']['placeholder'] = 'orob2b.order.form.address.choose_or_create';
     }
     $builder->add('accountAddress', 'genemu_jqueryselect2_choice', $accountAddressOptions);
     $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) use($isManualEditGranted) {
         if (!$isManualEditGranted) {
             $event->setData(null);
         }
         $form = $event->getForm();
         if (!$form->has('accountAddress')) {
             return;
         }
         $identifier = $form->get('accountAddress')->getData();
         if ($identifier === null) {
             return;
         }
         //Enter manually or Account/AccountUser address
         $orderAddress = $event->getData();
         $address = null;
         if ($identifier) {
             $address = $this->orderAddressManager->getEntityByIdentifier($identifier);
         }
         if ($orderAddress || $address) {
             $event->setData($this->orderAddressManager->updateFromAbstract($address, $orderAddress));
         }
     }, -10);
 }
 public function testGetEntityByIdentifier()
 {
     $entity = $this->getEntity('OroB2B\\Bundle\\AccountBundle\\Entity\\AccountUserAddress', 1);
     $em = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
     $em->expects($this->exactly(2))->method('find')->with($this->isType('string'), $this->isType('integer'))->will($this->onConsecutiveCalls($entity, null));
     $this->registry->expects($this->any())->method('getManagerForClass')->willReturn($em);
     $this->manager->addEntity('au', 'OroB2B\\Bundle\\AccountBundle\\Entity\\AccountUserAddress');
     $this->assertEquals($entity, $this->manager->getEntityByIdentifier('au_1'));
     $this->assertNull($this->manager->getEntityByIdentifier('au_2'));
 }