示例#1
0
 /**
  * Add owner field to forms
  *
  * @param BeforeFormRenderEvent $event
  */
 public function addOwnerField(BeforeFormRenderEvent $event)
 {
     $environment = $event->getTwigEnvironment();
     $data = $event->getFormData();
     $form = $event->getForm();
     $label = false;
     $entityProvider = $this->configManager->getProvider('entity');
     if (is_object($form->vars['value'])) {
         $className = ClassUtils::getClass($form->vars['value']);
         if (class_exists($className) && $entityProvider->hasConfig($className, 'owner')) {
             $config = $entityProvider->getConfig($className, 'owner');
             $label = $config->get('label');
         }
     }
     $ownerField = $environment->render("OroOrganizationBundle::owner.html.twig", array('form' => $form, 'label' => $label));
     /**
      * Setting owner field as first field in first data block
      */
     if (!empty($data['dataBlocks'])) {
         if (isset($data['dataBlocks'][0]['subblocks'])) {
             if (!isset($data['dataBlocks'][0]['subblocks'][0])) {
                 $data['dataBlocks'][0]['subblocks'][0] = ['data' => []];
             }
             array_unshift($data['dataBlocks'][0]['subblocks'][0]['data'], $ownerField);
         }
     }
     $event->setFormData($data);
 }
 public function testEvent()
 {
     $env = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock();
     $formView = $this->getMockBuilder('Symfony\\Component\\Form\\FormView')->disableOriginalConstructor()->getMock();
     $formData = array('test');
     $event = new BeforeFormRenderEvent($formView, $formData, $env);
     $this->assertEquals($formView, $event->getForm());
     $this->assertEquals($formData, $event->getFormData());
     $this->assertEquals($env, $event->getTwigEnvironment());
     $formDataNew = array('test_new');
     $event->setFormData($formDataNew);
     $this->assertEquals($formDataNew, $event->getFormData());
 }
 /**
  * Add owner field to forms
  *
  * @param BeforeFormRenderEvent $event
  */
 public function addOwnerField(BeforeFormRenderEvent $event)
 {
     $environment = $event->getTwigEnvironment();
     $data = $event->getFormData();
     $form = $event->getForm();
     $ownerField = $environment->render("OroOrganizationBundle::owner.html.twig", array('form' => $form));
     /**
      * Setting owner field as last field in first data block
      */
     if (!empty($data['dataBlocks'])) {
         if (isset($data['dataBlocks'][0]['subblocks'])) {
             $data['dataBlocks'][0]['subblocks'][0]['data'][] = $ownerField;
         }
     }
     $event->setFormData($data);
 }
示例#4
0
 /**
  * Add owner field to forms
  *
  * @param BeforeFormRenderEvent $event
  */
 public function addDataChannelField(BeforeFormRenderEvent $event)
 {
     $routename = $this->request->attributes->get('_route');
     if (strrpos($routename, 'oro_embedded_form_') === 0) {
         $env = $event->getTwigEnvironment();
         $data = $event->getFormData();
         $form = $event->getForm();
         $dataChannelField = $env->render('OroCRMChannelBundle:Form:dataChannelField.html.twig', ['form' => $form]);
         /**
          * Setting dataChannel field as first field in first data block
          */
         if (!empty($data['dataBlocks'])) {
             if (isset($data['dataBlocks'][0]['subblocks'])) {
                 array_unshift($data['dataBlocks'][0]['subblocks'][0]['data'], $dataChannelField);
             }
         }
         $event->setFormData($data);
     }
 }
 /**
  * Add owner field to forms
  *
  * @param BeforeFormRenderEvent $event
  */
 public function addBranchField(BeforeFormRenderEvent $event)
 {
     if (!$this->request) {
         return;
     }
     $routename = $this->request->attributes->get('_route');
     if (strrpos($routename, 'oro_embedded_form_') === 0) {
         $env = $event->getTwigEnvironment();
         $data = $event->getFormData();
         $form = $event->getForm();
         $branchField = $env->render('DiamanteEmbeddedFormBundle:Form:branchField.html.twig', ['form' => $form]);
         /**
          * Setting branch field as last field in first data block
          */
         if (!empty($data['dataBlocks'])) {
             if (isset($data['dataBlocks'][0]['subblocks'])) {
                 array_splice($data['dataBlocks'][0]['subblocks'][0]['data'], 1, 0, $branchField);
             }
         }
         $event->setFormData($data);
     }
 }