/** * Proces post before form handleRequest * * @param Post $post */ private function processPost(Post $post) { // Define slug for this 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); } // Check if gallery exists if ($post->getGallery() == null) { $gallery = new Gallery(); $gallery->setName($post->getTitle()); $post->setGallery($gallery); } return $post; }
/** * 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; }