Exemplo n.º 1
0
 /**
  * @DI\Observe("widget_innova_path_widget_configuration")
  *
  * @param ConfigureWidgetEvent $event
  */
 public function onConfigure(ConfigureWidgetEvent $event)
 {
     $instance = $event->getInstance();
     $config = $this->pathManager->getWidgetConfig($instance);
     $form = $this->formFactory->create('innova_path_widget_config', $config);
     $content = $this->twig->render('InnovaPathBundle:Widget:config.html.twig', ['form' => $form->createView(), 'instance' => $instance, 'tags' => $this->tagManager->getPlatformTags()]);
     $event->setContent($content);
     $event->stopPropagation();
 }
Exemplo n.º 2
0
 /**
  * @param WidgetInstance $widgetInstance
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  * @return array
  *
  * @Route(
  *      "/widget/config/{widgetInstance}",
  *      name= "innova_path_widget_config"
  * )
  * @Method("POST")
  * @Template("InnovaPathBundle:Widget:config.html.twig")
  */
 public function updateWidgetAction(WidgetInstance $widgetInstance, Request $request)
 {
     // User can not edit the Widget
     if (!$this->authorizationChecker->isGranted('edit', $widgetInstance)) {
         throw new AccessDeniedException();
     }
     $config = $this->pathManager->getWidgetConfig($widgetInstance);
     if (null === $config) {
         $config = new PathWidgetConfig();
         $config->setWidgetInstance($widgetInstance);
     }
     $form = $this->formFactory->create('innova_path_widget_config', $config);
     $form->bind($request);
     if ($form->isValid()) {
         // Remove tags
         $tagsToRemove = $form->get('removeTags')->getData();
         if (!empty($tagsToRemove)) {
             // Search the Tag by ID
             $existingTags = $config->getTags()->toArray();
             $toRemoveArray = array_filter($existingTags, function ($entry) use($tagsToRemove) {
                 return in_array($entry->getId(), $tagsToRemove);
             });
             foreach ($toRemoveArray as $toRemove) {
                 $config->removeTag($toRemove);
             }
         }
         // Add tags
         $tags = $form->get('tags')->getData();
         if (!empty($tags)) {
             // Ge the list of Tags from data String
             $tags = explode(',', $tags);
             $uniqueTags = array();
             foreach ($tags as $tag) {
                 $value = trim($tag);
                 if (!empty($value)) {
                     $uniqueTags[strtolower($value)] = $value;
                 }
             }
             foreach ($uniqueTags as $tagName) {
                 $tagObject = $this->tagManager->getOnePlatformTagByName($tagName);
                 if (!empty($tagObject)) {
                     $config->addTag($tagObject);
                 }
             }
         }
         $this->om->persist($config);
         $this->om->flush();
         return new Response('success', 204);
     }
     return array('form' => $form->createView(), 'instance' => $widgetInstance, 'tags' => $this->tagManager->getPlatformTags());
 }