protected function updateBaseTranslation(Blog $blog) { $blog->setTranslatableLocale($this->getRequest()->getLocale()); foreach ($blog->getTranslations() as $translation) { /** @var BlogTranslation $translation */ $translation->updateParentFields(); } }
/** * @ORM\PrePersist */ public function updateParentFields() { if ($this->object->getLocale() == $this->locale) { $method = 'set' . ucfirst($this->field); if (method_exists($this->object, $method)) { $this->object->{$method}($this->getContent()); } } }
/** * @Method("POST") */ public function orderImagesAction(Blog $blog) { $order = $this->getRequest()->get('images', array()); $images = $blog->getImages(); $em = $this->getDoctrine()->getManager(); $i = 1; foreach ($order as $id) { foreach ($images as $image) { /** @var BlogImage $image */ if ($image->getId() == $id) { $image->setStackOrder($i++) && $em->persist($image); } } } $em->flush(); return new Response('ok'); }