src/Kunstmaan/NodeBundle/Helper/NodeAdmin/NodeAdminPublisher.php
public function publish(NodeTranslation $nodeTranslation, $user = null)
    {
        if (false === $this->authorizationChecker->isGranted(PermissionMap::PERMISSION_PUBLISH, $nodeTranslation->getNode())) {
            throw new AccessDeniedException();
        }

        if (is_null($user)) {
            $user = $this->tokenStorage->getToken()->getUser();
        }

        $node = $nodeTranslation->getNode();

        $nodeVersion = $nodeTranslation->getNodeVersion('draft');
        if (!is_null($nodeVersion)) {
            $page = $nodeVersion->getRef($this->em);
            /** @var $nodeVersion NodeVersion */
            $nodeVersion = $this->createPublicVersion($page, $nodeTranslation, $nodeVersion, $user);
            $nodeTranslation = $nodeVersion->getNodeTranslation();
        } else {
            $nodeVersion = $nodeTranslation->getPublicNodeVersion();
        }

        $page = $nodeVersion->getRef($this->em);

        $this->eventDispatcher->dispatch(
            Events::PRE_PUBLISH,
            new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
        );
        $nodeTranslation
            ->setOnline(true)
            ->setPublicNodeVersion($nodeVersion)
            ->setUpdated(new \DateTime());
        $this->em->persist($nodeTranslation);
        $this->em->flush();

        // Remove scheduled task
        $this->unSchedulePublish($nodeTranslation);

        $this->eventDispatcher->dispatch(
            Events::POST_PUBLISH,
            new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
        );
    }
public function publish(NodeTranslation $nodeTranslation, $user = null)
    {
        if (false === $this->authorizationChecker->isGranted(PermissionMap::PERMISSION_PUBLISH, $nodeTranslation->getNode())) {
            throw new AccessDeniedException();
        }

        if (is_null($user)) {
            $user = $this->tokenStorage->getToken()->getUser();
        }

        $node = $nodeTranslation->getNode();

        $nodeVersion = $nodeTranslation->getNodeVersion('draft');
        if (!is_null($nodeVersion)) {
            $page = $nodeVersion->getRef($this->em);
            /** @var $nodeVersion NodeVersion */
            $nodeVersion = $this->createPublicVersion($page, $nodeTranslation, $nodeVersion, $user);
            $nodeTranslation = $nodeVersion->getNodeTranslation();
        } else {
            $nodeVersion = $nodeTranslation->getPublicNodeVersion();
        }

        $page = $nodeVersion->getRef($this->em);

        $this->eventDispatcher->dispatch(
            Events::PRE_PUBLISH,
            new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
        );
        $nodeTranslation
            ->setOnline(true)
            ->setPublicNodeVersion($nodeVersion)
            ->setUpdated(new \DateTime());
        $this->em->persist($nodeTranslation);
        $this->em->flush();

        // Remove scheduled task
        $this->unSchedulePublish($nodeTranslation);

        $this->eventDispatcher->dispatch(
            Events::POST_PUBLISH,
            new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
        );
    }
public function publish ( NodeTranslation $ nodeTranslation , $ user = null ) { if ( false === $ this -> authorizationChecker -> isGranted ( PermissionMap :: PERMISSION_PUBLISH , $ nodeTranslation -> getNode ( ) ) ) { throw new AccessDeniedException ( ) ; } if ( is_null ( $ user ) ) { $ user = $ this -> tokenStorage -> getToken ( ) -> getUser ( ) ; } $ node = $ nodeTranslation -> getNode ( ) ; $ nodeVersion = $ nodeTranslation -> getNodeVersion ( 'draft' ) ; if ( ! is_null ( $ nodeVersion ) ) { $ page = $ nodeVersion -> getRef ( $ this -> em ) ; /** @var $nodeVersion NodeVersion */ $ nodeVersion = $ this -> createPublicVersion ( $ page , $ nodeTranslation , $ nodeVersion , $ user ) ; $ nodeTranslation = $ nodeVersion -> getNodeTranslation ( ) ; } else { $ nodeVersion = $ nodeTranslation -> getPublicNodeVersion ( ) ; } $ page = $ nodeVersion -> getRef ( $ this -> em ) ; $ this -> eventDispatcher -> dispatch ( Events :: PRE_PUBLISH , new NodeEvent ( $ node , $ nodeTranslation , $ nodeVersion , $ page ) ) ; $ nodeTranslation -> setOnline ( true ) -> setPublicNodeVersion ( $ nodeVersion ) -> setUpdated ( new \ DateTime ( ) ) ; $ this -> em -> persist ( $ nodeTranslation ) ; $ this -> em -> flush ( ) ; // Remove scheduled task $ this -> unSchedulePublish ( $ nodeTranslation ) ; $ this -> eventDispatcher -> dispatch ( Events :: POST_PUBLISH , new NodeEvent ( $ node , $ nodeTranslation , $ nodeVersion , $ page ) ) ; }
If there is a draft version it'll try to publish the draft first. Makse snese because if you want to publish the public version you don't publish but you save.

@param NodeTranslation $nodeTranslation
@param null|BaseUser   $user

@throws AccessDeniedException
If there is a draft version it ll try to publish the draft first . Makse snese because if you want to publish the public version you don t publish but you save .