public function editAction(Request $request, $id)
    {
        /** @var ContentManager $manager */
        $manager = $this->get('opifer.content.content_manager');
        $em = $manager->getEntityManager();
        $content = $manager->getRepository()->find($id);
        $content = $manager->createMissingValueSet($content);

        // Load the contentTranslations for the content group
        if ($content->getTranslationGroup() !== null) {
            $contentTranslations = $content->getTranslationGroup()->getContents()->filter(function($contentTranslation) use ($content) {
                return $contentTranslation->getId() !== $content->getId();
            });

            $content->setContentTranslations($contentTranslations);
        }

        $form = $this->createForm(ContentType::class, $content);

        $originalContentItems = new ArrayCollection();
        foreach ($content->getContentTranslations() as $contentItem) {
            $originalContentItems->add($contentItem);
        }

        $form->handleRequest($request);

        if ($form->isValid()) {
            if (null === $content->getPublishAt()) {
                $content->setPublishAt($content->getCreatedAt());
            }

            if ($content->getTranslationGroup() === null) {
                // Init new group
                $translationGroup = new TranslationGroup();
                $content->setTranslationGroup($translationGroup);
            }

            // Make sure all the contentTranslations have the same group as content
            $contentTranslationIds = [$content->getId()];
            foreach($content->getContentTranslations() as $contentTranslation) {
                if ($contentTranslation->getTranslationGroup() === null) {
                    $contentTranslation->setTranslationGroup($content->getTranslationGroup());
                    $em->persist($contentTranslation);
                }

                $contentTranslationIds[] = $contentTranslation->getId();
            }

            // Remove possible contentTranslations from the translationGroup
            $queryBuilder = $manager->getRepository()->createQueryBuilder('c');
            $queryBuilder->update()
                ->set('c.translationGroup', 'NULL')
                ->where($queryBuilder->expr()->eq('c.translationGroup', $content->getTranslationGroup()->getId()))
                ->where($queryBuilder->expr()->notIn('c.id', $contentTranslationIds))
                ->getQuery()
                ->execute();

            $em->persist($content);

            $em->flush();

            return $this->redirectToRoute('opifer_content_content_index');
        }

        return $this->render($this->getParameter('opifer_content.content_edit_view'), [
            'content' => $content,
            'form' => $form->createView(),
        ]);
    }
public function editAction(Request $request, $id)
    {
        /** @var ContentManager $manager */
        $manager = $this->get('opifer.content.content_manager');
        $em = $manager->getEntityManager();
        $content = $manager->getRepository()->find($id);
        $content = $manager->createMissingValueSet($content);

        // Load the contentTranslations for the content group
        if ($content->getTranslationGroup() !== null) {
            $contentTranslations = $content->getTranslationGroup()->getContents()->filter(function($contentTranslation) use ($content) {
                return $contentTranslation->getId() !== $content->getId();
            });

            $content->setContentTranslations($contentTranslations);
        }

        $form = $this->createForm(ContentType::class, $content);

        $originalContentItems = new ArrayCollection();
        foreach ($content->getContentTranslations() as $contentItem) {
            $originalContentItems->add($contentItem);
        }

        $form->handleRequest($request);

        if ($form->isValid()) {
            if (null === $content->getPublishAt()) {
                $content->setPublishAt($content->getCreatedAt());
            }

            if ($content->getTranslationGroup() === null) {
                // Init new group
                $translationGroup = new TranslationGroup();
                $content->setTranslationGroup($translationGroup);
            }

            // Make sure all the contentTranslations have the same group as content
            $contentTranslationIds = [$content->getId()];
            foreach($content->getContentTranslations() as $contentTranslation) {
                if ($contentTranslation->getTranslationGroup() === null) {
                    $contentTranslation->setTranslationGroup($content->getTranslationGroup());
                    $em->persist($contentTranslation);
                }

                $contentTranslationIds[] = $contentTranslation->getId();
            }

            // Remove possible contentTranslations from the translationGroup
            $queryBuilder = $manager->getRepository()->createQueryBuilder('c');
            $queryBuilder->update()
                ->set('c.translationGroup', 'NULL')
                ->where($queryBuilder->expr()->eq('c.translationGroup', $content->getTranslationGroup()->getId()))
                ->where($queryBuilder->expr()->notIn('c.id', $contentTranslationIds))
                ->getQuery()
                ->execute();

            $em->persist($content);

            $em->flush();

            return $this->redirectToRoute('opifer_content_content_index');
        }

        return $this->render($this->getParameter('opifer_content.content_edit_view'), [
            'content' => $content,
            'form' => $form->createView(),
        ]);
    }
public function editAction ( Request $ request , $ id ) { /** @var ContentManager $manager */ $ manager = $ this -> get ( 'opifer.content.content_manager' ) ; $ em = $ manager -> getEntityManager ( ) ; $ content = $ manager -> getRepository ( ) -> find ( $ id ) ; $ content = $ manager -> createMissingValueSet ( $ content ) ; // Load the contentTranslations for the content group if ( $ content -> getTranslationGroup ( ) !== null ) { $ contentTranslations = $ content -> getTranslationGroup ( ) -> getContents ( ) -> filter ( function ( $ contentTranslation ) use ( $ content ) { return $ contentTranslation -> getId ( ) !== $ content -> getId ( ) ; } ) ; $ content -> setContentTranslations ( $ contentTranslations ) ; } $ form = $ this -> createForm ( ContentType :: class , $ content ) ; $ originalContentItems = new ArrayCollection ( ) ; foreach ( $ content -> getContentTranslations ( ) as $ contentItem ) { $ originalContentItems -> add ( $ contentItem ) ; } $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { if ( null === $ content -> getPublishAt ( ) ) { $ content -> setPublishAt ( $ content -> getCreatedAt ( ) ) ; } if ( $ content -> getTranslationGroup ( ) === null ) { // Init new group $ translationGroup = new TranslationGroup ( ) ; $ content -> setTranslationGroup ( $ translationGroup ) ; } // Make sure all the contentTranslations have the same group as content $ contentTranslationIds = [ $ content -> getId ( ) ] ; foreach ( $ content -> getContentTranslations ( ) as $ contentTranslation ) { if ( $ contentTranslation -> getTranslationGroup ( ) === null ) { $ contentTranslation -> setTranslationGroup ( $ content -> getTranslationGroup ( ) ) ; $ em -> persist ( $ contentTranslation ) ; } $ contentTranslationIds [ ] = $ contentTranslation -> getId ( ) ; } // Remove possible contentTranslations from the translationGroup $ queryBuilder = $ manager -> getRepository ( ) -> createQueryBuilder ( 'c' ) ; $ queryBuilder -> update ( ) -> set ( 'c.translationGroup' , 'NULL' ) -> where ( $ queryBuilder -> expr ( ) -> eq ( 'c.translationGroup' , $ content -> getTranslationGroup ( ) -> getId ( ) ) ) -> where ( $ queryBuilder -> expr ( ) -> notIn ( 'c.id' , $ contentTranslationIds ) ) -> getQuery ( ) -> execute ( ) ; $ em -> persist ( $ content ) ; $ em -> flush ( ) ; return $ this -> redirectToRoute ( 'opifer_content_content_index' ) ; } return $ this -> render ( $ this -> getParameter ( 'opifer_content.content_edit_view' ) , [ 'content' => $ content , 'form' => $ form -> createView ( ) , ] ) ; }
Edit the details of Content.

@param Request $request
@param int     $id

@return Response
Edit the details of Content .