/**
  * @DI\Observe("widget_blog_list_configuration")
  */
 public function onWidgetListConfigure(ConfigureWidgetEvent $event)
 {
     $widgetBlogList = new WidgetBlogList();
     $widgetBlogList->setWidgetListBlogs($this->widgetManager->getWidgetListBlogs($event->getInstance()));
     $widgetBlogList->setWidgetDisplayListBlogs($this->widgetManager->getWidgetListOptions($event->getInstance())->getDisplayStyle());
     $form = $this->formFactory->create($this->widgetListType, $widgetBlogList);
     $content = $this->templatingEngine->render('IcapBlogBundle:widget:listConfigure.html.twig', array('form' => $form->createView(), 'widgetInstance' => $event->getInstance()));
     $event->setContent($content);
 }
 /**
  * @Route("/icap_blog/widget/list/{id}/config", name="icap_blog_widget_list_configure", requirements={"id" = "\d+"})
  * @Method("POST")
  */
 public function updateWidgetBlogList(Request $request, WidgetInstance $widgetInstance)
 {
     if (!$this->get('security.authorization_checker')->isGranted('edit', $widgetInstance)) {
         throw new AccessDeniedException();
     }
     $originalWidgetListBlogs = $this->getWidgetManager()->getWidgetListBlogs($widgetInstance);
     $originalWidgetListBlogs = new ArrayCollection($originalWidgetListBlogs);
     $widgetListOptions = $this->getWidgetManager()->getWidgetListOptions($widgetInstance);
     $widgetBlogList = new WidgetBlogList();
     $widgetBlogList->setWidgetListBlogs($originalWidgetListBlogs);
     $widgetBlogList->setWidgetDisplayListBlogs($widgetListOptions->getDisplayStyle());
     //On rajoute une troisieme option translator
     /** @var Form $form */
     $form = $this->get('form.factory')->create($this->get('icap_blog.form.widget_list'), $widgetBlogList);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $entityManager = $this->get('doctrine.orm.entity_manager');
         $widgetListBlogs = $widgetBlogList->getWidgetListBlogs();
         //On recupère la valeur du bouton radio en base
         $widgetDisplayListBlogs = $widgetBlogList->getWidgetListBlogs();
         //Comparaison entre la valeur donnée en formulaire et celle en base
         foreach ($widgetListBlogs as $widgetListBlog) {
             if ($originalWidgetListBlogs->contains($widgetListBlog)) {
                 $originalWidgetListBlogs->removeElement($widgetListBlog);
             } else {
                 $widgetListBlog->setWidgetInstance($widgetInstance);
                 $entityManager->persist($widgetListBlog);
             }
         }
         foreach ($originalWidgetListBlogs as $originalWidgetListBlog) {
             $entityManager->remove($originalWidgetListBlog);
         }
         $widgetListOptions->setDisplayStyle($widgetBlogList->getWidgetDisplayListBlogs());
         $entityManager->persist($widgetListOptions);
         $entityManager->flush();
         return new Response('', Response::HTTP_NO_CONTENT);
     }
     return $this->render('IcapBlogBundle:widget:listConfigure.html.twig', array('form' => $form->createView(), 'widgetInstance' => $widgetInstance));
 }