/**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     if (!$options['disable_customer_datasource_types']) {
         return;
     }
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         /** @var Integration $data */
         $data = $event->getData();
         $form = $event->getForm();
         if ($data === null) {
             return;
         }
         // Remove integration types that could be created only in scope of the channel
         // if type is already set, then keep choice list as is
         $sourceTypes = $this->settingsProvider->getSourceIntegrationTypes();
         if (!in_array($data->getType(), $sourceTypes)) {
             $field = $form->get('type');
             $config = $field->getConfig()->getOptions();
             foreach ($sourceTypes as $sourceType) {
                 unset($config['choices'][$sourceType]);
             }
             FormUtils::replaceField($form, 'type', ['choices' => $config['choices']], ['choice_list']);
         }
     }, 100);
 }
Beispiel #2
0
 /**
  * @param SettingsProvider $settingsProvider
  */
 protected function createChannelsForIntegrations(SettingsProvider $settingsProvider)
 {
     // create channels for integrations
     $types = $settingsProvider->getSourceIntegrationTypes();
     $integrations = $this->em->getRepository('OroIntegrationBundle:Channel')->findBy(['type' => $types]);
     /** @var Integration $integration */
     foreach ($integrations as $integration) {
         $builder = $this->container->get('orocrm_channel.builder.factory')->createBuilderForIntegration($integration);
         $builder->setOwner($integration->getOrganization());
         $builder->setDataSource($integration);
         $builder->setStatus($integration->getEnabled() ? Channel::STATUS_ACTIVE : Channel::STATUS_INACTIVE);
         $builder->setName($integration->getName() . ' channel');
         $channel = $builder->getChannel();
         $this->em->persist($builder->getChannel());
         $this->em->flush();
         foreach ($channel->getEntities() as $entity) {
             $this->fillChannelToEntity($channel, $entity);
         }
     }
 }