/** * Add a tag * * @Route("/tag/add", name="portfolio_tag_add") */ public function addTagAction() { $em = $this->get('doctrine')->getManager(); $requestStack = $this->getRequestStack(); $tag = new Tag(); $tag->setName($requestStack->get('tag')); $em->persist($tag); $em->flush(); return new Response(json_encode(array('html' => $this->get('twig')->render('BigfootMediaBundle:snippets:tag_option.html.twig', array('tag' => $tag)))), 200, array('Content-Type', 'application/json')); }
/** * @param mixed $string * @return ArrayCollection|mixed */ public function reverseTransform($string) { $arrayTags = explode(self::SEPARATOR, $string); $tags = new ArrayCollection(); $defaultCategory = $this->getDefaultCategory(); $em = $this->entityManager; $tagRepo = $em->getRepository('BigfootCoreBundle:Tag'); foreach ($arrayTags as $tag) { if ($tag) { if (!($tagEntity = $tagRepo->findOneByName($tag))) { $tagEntity = new Tag(); $tagEntity->setName($tag); $tagEntity->setCategory($defaultCategory); } $tags->add($tagEntity); } } return $tags; }