src/Kunstmaan/NodeBundle/Repository/NodeTranslationRepository.php
public function createNodeTranslationFor(
        HasNodeInterface $hasNode,
        $lang,
        Node $node,
        BaseUser $owner
    ) {
        $em = $this->getEntityManager();
        $className = ClassLookup::getClass($hasNode);
        if (!$hasNode->getId() > 0) {
            throw new \InvalidArgumentException(
                'The entity of class ' . $className .
                ' has no id, maybe you forgot to flush first'
            );
        }

        $nodeTranslation = new NodeTranslation();
        $nodeTranslation
            ->setNode($node)
            ->setLang($lang)
            ->setTitle($hasNode->getTitle())
            ->setOnline(false)
            ->setWeight(0);

        $em->persist($nodeTranslation);

        $nodeVersion = $em->getRepository('KunstmaanNodeBundle:NodeVersion')
            ->createNodeVersionFor(
                $hasNode,
                $nodeTranslation,
                $owner,
                null
            );

        $nodeTranslation->setPublicNodeVersion($nodeVersion);
        $em->persist($nodeTranslation);
        $em->flush();
        $em->refresh($nodeTranslation);
        $em->refresh($node);

        return $nodeTranslation;
    }
public function createNodeTranslationFor(
        HasNodeInterface $hasNode,
        $lang,
        Node $node,
        BaseUser $owner
    ) {
        $em = $this->getEntityManager();
        $className = ClassLookup::getClass($hasNode);
        if (!$hasNode->getId() > 0) {
            throw new \InvalidArgumentException(
                'The entity of class ' . $className .
                ' has no id, maybe you forgot to flush first'
            );
        }

        $nodeTranslation = new NodeTranslation();
        $nodeTranslation
            ->setNode($node)
            ->setLang($lang)
            ->setTitle($hasNode->getTitle())
            ->setOnline(false)
            ->setWeight(0);

        $em->persist($nodeTranslation);

        $nodeVersion = $em->getRepository('KunstmaanNodeBundle:NodeVersion')
            ->createNodeVersionFor(
                $hasNode,
                $nodeTranslation,
                $owner,
                null
            );

        $nodeTranslation->setPublicNodeVersion($nodeVersion);
        $em->persist($nodeTranslation);
        $em->flush();
        $em->refresh($nodeTranslation);
        $em->refresh($node);

        return $nodeTranslation;
    }
public function createNodeTranslationFor ( HasNodeInterface $ hasNode , $ lang , Node $ node , BaseUser $ owner ) { $ em = $ this -> getEntityManager ( ) ; $ className = ClassLookup :: getClass ( $ hasNode ) ; if ( ! $ hasNode -> getId ( ) > 0 ) { throw new \ InvalidArgumentException ( 'The entity of class ' . $ className . ' has no id, maybe you forgot to flush first' ) ; } $ nodeTranslation = new NodeTranslation ( ) ; $ nodeTranslation -> setNode ( $ node ) -> setLang ( $ lang ) -> setTitle ( $ hasNode -> getTitle ( ) ) -> setOnline ( false ) -> setWeight ( 0 ) ; $ em -> persist ( $ nodeTranslation ) ; $ nodeVersion = $ em -> getRepository ( 'KunstmaanNodeBundle:NodeVersion' ) -> createNodeVersionFor ( $ hasNode , $ nodeTranslation , $ owner , null ) ; $ nodeTranslation -> setPublicNodeVersion ( $ nodeVersion ) ; $ em -> persist ( $ nodeTranslation ) ; $ em -> flush ( ) ; $ em -> refresh ( $ nodeTranslation ) ; $ em -> refresh ( $ node ) ; return $ nodeTranslation ; }
Create a node translation for a given node

@param HasNodeInterface $hasNode The hasNode
@param string           $lang    The locale
@param Node             $node    The node
@param BaseUser         $owner   The user

@throws \InvalidArgumentException

@return NodeTranslation
Create a node translation for a given node