コード例 #1
0
ファイル: Persister.php プロジェクト: bigfishcmf/bigfishcmf
 /**
  * @param Instance $instance
  * @param array $data
  */
 public function duplicate(array $data = array(), ResourceHasInstance $resourceHasInstance, Resource $resource)
 {
     $alreadyExists = $this->objectManager->getRepository('BigfishPagekitBundle:ResourceHasInstance')->findBy(array('instance' => $resourceHasInstance->getInstance(), 'resource' => $resource));
     $this->update($resourceHasInstance, $data);
     if (!$alreadyExists) {
         $newResourceHasInstance = clone $resourceHasInstance;
         $newResourceHasInstance->setResource($resource);
         $this->objectManager->persist($newResourceHasInstance);
         $this->objectManager->flush();
         return true;
     }
     return false;
 }
コード例 #2
0
 /**
  * @param Request $request
  * @param ResourceHasInstance $resourceHasInstance
  * @param Resource $resource
  * @return RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function duplicateAction(Request $request, ResourceHasInstance $resourceHasInstance, Resource $resource)
 {
     $culture = $this->languageManager->getCulture();
     /** @var \Bigfish\Bundle\EavBundle\Entity\Module $module */
     $module = $resourceHasInstance->getInstance()->getComponent()->getModule();
     // Add a custom form type for the component itself.
     $formBuilder = $this->createFormBuilder()->add('instance', new InstanceType($resourceHasInstance));
     /** @var \Bigfish\Bundle\EavBundle\Form\FormBuilder $form */
     $form = $this->get('eav.form.builder')->createFormBuilder($module, array('container' => $resourceHasInstance->getInstance()->getContainer()), array(), $formBuilder)->getForm();
     if ($this->formHandler->handleDuplicate($form, $request, $resourceHasInstance, $resource)) {
         return new JsonResponse(array("success" => true));
     }
     return $this->render('BigfishPagekitBundle:Component:edit.html.twig', array('form' => $form->createView(), 'actionUrl' => $this->generateUrl('pagekit_component_duplicate', array('resourceHasInstance' => $resourceHasInstance->getId(), 'resource' => $resource->getId(), 'bflanguage' => $culture))));
 }
コード例 #3
0
ファイル: FormHandler.php プロジェクト: bigfishcmf/bigfishcmf
 /**
  * @param FormInterface $form
  * @param Request $request
  * @param Resource $resource
  * @return bool
  */
 public function handleUpdate(FormInterface $form, Request $request, ResourceHasInstance $resourceHasInstance)
 {
     $form->setData($this->eavPersister->find($resourceHasInstance->getInstance()->getContainer()));
     if ($this->handle($form, $request)) {
         $this->pagekitPersister->update($resourceHasInstance, $form->getData());
         return true;
     }
     return false;
 }