/** * Proces new or updated posts * * @param Post $post */ private function processForm(Post $post) { if ($post->getSlug() == null) { $em = $this->getDoctrine()->getManager(); $i = 1; $slug = Slug::slugify($post->getTitle()); $exists = $em->getRepository("OesteveGrupetaBundle:Post")->findOneBy(array('slug' => $slug)); while ($exists != null) { $slug = Slug::slugify($post->getTitle() . '-' . $i++); $exists = $em->getRepository("OesteveGrupetaBundle:Post")->findOneBy(array('slug' => $slug)); } $post->setSlug($slug); } //All post in this secction are in the front $post->setFront(true); return $post; }