src/Kunstmaan/PagePartBundle/Helper/Services/PagePartCreatorService.php
public function addPagePartToPage($nodeOrInternalName, PagePartInterface $pagePart, $language, $context = 'main', $position = null)
    {
        // Find the correct page instance.
        $node = $this->getNode($nodeOrInternalName);
        /** @var $translation NodeTranslation */
        $translation = $node->getNodeTranslation($language, true);
        /** @var HasPagePartsInterface $page */
        $page = $translation->getRef($this->em);

        // Find latest position.
        if (is_null($position)) {
            $pageParts = $this->pagePartRepo->getPagePartRefs($page, $context);
            $position = count($pageParts) + 1;
        }

        $this->em->persist($pagePart);
        $this->em->flush();

        $this->pagePartRepo->addPagePart($page, $pagePart, $position, $context);
    }
public function addPagePartToPage($nodeOrInternalName, PagePartInterface $pagePart, $language, $context = 'main', $position = null)
    {
        // Find the correct page instance.
        $node = $this->getNode($nodeOrInternalName);
        /** @var $translation NodeTranslation */
        $translation = $node->getNodeTranslation($language, true);
        /** @var HasPagePartsInterface $page */
        $page = $translation->getRef($this->em);

        // Find latest position.
        if (is_null($position)) {
            $pageParts = $this->pagePartRepo->getPagePartRefs($page, $context);
            $position = count($pageParts) + 1;
        }

        $this->em->persist($pagePart);
        $this->em->flush();

        $this->pagePartRepo->addPagePart($page, $pagePart, $position, $context);
    }
public function addPagePartToPage ( $ nodeOrInternalName , PagePartInterface $ pagePart , $ language , $ context = 'main' , $ position = null ) { // Find the correct page instance. $ node = $ this -> getNode ( $ nodeOrInternalName ) ; /** @var $translation NodeTranslation */ $ translation = $ node -> getNodeTranslation ( $ language , true ) ; /** @var HasPagePartsInterface $page */ $ page = $ translation -> getRef ( $ this -> em ) ; // Find latest position. if ( is_null ( $ position ) ) { $ pageParts = $ this -> pagePartRepo -> getPagePartRefs ( $ page , $ context ) ; $ position = count ( $ pageParts ) + 1 ; } $ this -> em -> persist ( $ pagePart ) ; $ this -> em -> flush ( ) ; $ this -> pagePartRepo -> addPagePart ( $ page , $ pagePart , $ position , $ context ) ; }
Add a single pagepart to an existing page for a specific language, in an optional position.

@param mixed(Node|string)  $nodeOrInternalName
A Node instance or the internal name.
When the internal name is passed we'll get the node instance.
Based on the language we'll locate the correct Page instance.
@param pagePartInterface   $pagePart
A completely configured pagepart for this language
@param string              $language
The languagecode. nl|fr|en|.. . Just one.
@param string              $context
Where you want the pagepart to be
@param mixed(integer\NULL) $position
Leave null if you want to append at the end.
Otherwise set a position you would like and it'll inject the pagepart in that position.
It won't override pageparts but it will rather inject itself in that position and
push the other pageparts down.
Add a single pagepart to an existing page for a specific language in an optional position .