Sets the main node value of $content to $page.
Recompute $content if need.

@param AbstractClassContent $content
@param Page                 $page
512941
private function setMainNode(AbstractClassContent $content, Page $page)
    {
        if (null !== $content->getMainNode()) {
            return;
        }

        $content->setMainNode($page);

        if (null !== $this->entityManager) {
            $uow = $this->entityManager->getUnitOfWork();
            $meta = $this->entityManager->getClassMetadata(get_class($content));
            if ($uow->isEntityScheduled($content)) {
                $uow->recomputeSingleEntityChangeSet($meta, $content);
            } elseif ($uow->isEntityScheduled($page)) {
                $uow->computeChangeSet($meta, $content);
            }
        }
    }
781235
private function updateContentElements(AbstractClassContent $content, array $elementsData)
    {
        foreach ($elementsData as $key => $data) {
            if (in_array('Element\Keyword', $content->getAccept()[$key])) {
                $this->entityManager
                        ->getRepository('BackBee\ClassContent\Element\Keyword')
                        ->updateKeywordLinks($content, $data, $this->token);
            }
            $content->$key = $data;
        }

        return $this;
    }
1128418
protected function _set_content()
    {
        $frame = $this->_frame;
        $style = $frame->get_style();

        // if the element was pushed to a new page use the saved counter value, otherwise use the CSS reset value
        if ($style->counter_reset && ($reset = $style->counter_reset) !== "none") {
            $vars = preg_split('/\s+/', trim($reset), 2);
            $frame->reset_counter($vars[0], (isset($frame->_counters['__' . $vars[0]]) ? $frame->_counters['__' . $vars[0]] : (isset($vars[1]) ? $vars[1] : 0)));
        }

        if ($style->counter_increment && ($increment = $style->counter_increment) !== "none") {
            $frame->increment_counters($increment);
        }

        if ($style->content && $frame->get_node()->nodeName === "dompdf_generated") {
            $content = $this->_parse_content();
            // add generated content to the font subset
            // FIXME: This is currently too late because the font subset has already been generated.
            //        See notes in issue #750.
            if ($frame->get_dompdf()->getOptions()->getIsFontSubsettingEnabled() && $frame->get_dompdf()->get_canvas() instanceof CPDF) {
                $frame->get_dompdf()->get_canvas()->register_string_subset($style->font_family, $content);
            }

            $node = $frame->get_node()->ownerDocument->createTextNode($content);

            $new_style = $style->get_stylesheet()->create_style();
            $new_style->inherit($style);

            $new_frame = new Frame($node);
            $new_frame->set_style($new_style);

            Factory::decorate_frame($new_frame, $frame->get_dompdf(), $frame->get_root());
            $frame->append_child($new_frame);
        }
    }
231278
private static function indexContent(AbstractClassContent $content)
    {
        if (!self::hasIndexedElements($content)) {
            return;
        }

        foreach ($content->getProperty('indexation') as $indexedElement) {
            $indexedElement = (array) $indexedElement;
            list($value, $owner) = self::getIndexValue($content, $indexedElement[0]);

            $callback = array_key_exists(1, $indexedElement) ? $indexedElement[1] : null;
            if (null !== $callback) {
                $value = self::applyCallbacks($value, (array) $callback);
            }

            if (null !== $value && null !== $owner) {
                $index = new Indexation($content, $indexedElement[0], $owner, $value, serialize($callback));
                self::$em->getRepository('BackBee\ClassContent\Indexation')->save($index);
            }
        }
    }
322050
private function updatePageMenuPosition(Page $page)
    {
        $pageMenuRepository = $this->doctrine->getRepository('FulgurioLightCMSBundle:PageMenu');
        $em = $this->doctrine->getManager();
        $data = $this->request->get('page');
        if (isset($data['availableMenu']))
        {
            if (!is_null($page->getId()))
            {
                $menus = $page->getMenu();
                $alreadyInMenu = array();
                foreach ($menus as $menu)
                {
                    if (!in_array($menu->getLabel(), $data['availableMenu']))
                    {
                        $pageMenuRepository->upMenuPagesPosition($menu->getLabel(), $menu->getPosition() + 1);
                        $em->remove($menu);
                    }
                    else
                    {
                        $alreadyInMenu[] = $menu->getLabel();
                    }
                }
            }
            foreach ($data['availableMenu'] as $menuLabel)
            {
                // If it s a new page, or if it a page which we had a new menu
                if (!isset($alreadyInMenu) || !in_array($menuLabel, $alreadyInMenu))
                {
                    $menu = new PageMenu();
                    $menu->setPosition($pageMenuRepository->getNextMenuPosition($menuLabel));
                    $menu->setLabel($menuLabel);
                    $menu->setPage($page);
                    $em->persist($menu);
                }
            }
        }
        else if (!is_null($page->getId()))
        {
            $menus = $page->getMenu();
            foreach ($menus as $menu)
            {
                $pageMenuRepository->upMenuPagesPosition($menu->getLabel(), $menu->getPosition() + 1);
                $em->remove($menu);
            }
        }
    }
671814
protected function updateSeoPage(PageInterface $page)
    {
        if (!$this->seoPage) {
            return;
        }

        /*
         * Always prefer the page title, if set.
         * Do not use the (internal) page name as a fallback
         */
        if ($page->getTitle()) {
            $this->seoPage->setTitle($page->getTitle());
        }

        if ($page->getMetaDescription()) {
            $this->seoPage->addMeta('name', 'description', $page->getMetaDescription());
        }

        if ($page->getMetaKeyword()) {
            $this->seoPage->addMeta('name', 'keywords', $page->getMetaKeyword());
        }

        $this->seoPage->addMeta('property', 'og:type', 'article');
        $this->seoPage->addHtmlAttributes('prefix', 'og: http://ogp.me/ns#');
    }
926774
public static function pageSet(string $name, $value, ?string $page = null): void
    {
        if ($page === null) {
            $page = $_SERVER['PHP_SELF'];
        }
        self::set($name, $value, $page);
    }
1211676
public function removePageContent(\Haven\CmsBundle\Entity\PageContent $pageContents) {
        $this->page_contents->removeElement($pageContents);
    }
979706
public void setCurrentPage(int currentPage) throws CmsIllegalArgumentException {

        if (getSize() != 0) {
            if ((currentPage < 1) || (currentPage > getNumberOfPages())) {
                throw new CmsIllegalArgumentException(
                    Messages.get().container(Messages.ERR_LIST_INVALID_PAGE_1, new Integer(currentPage)));
            }
        }
        m_currentPage = currentPage;
    }
218943
public void setContent(Node content) {
        this.content = content;
        if (drawers.size() > 0) {
            drawers.get(0).setContent(content);
        } else {
            getChildren().add(this.content);
        }
    }
1343823
private void setCurrentPage(int page) {
        if (page >= totalPages) {
            this.currentPage = totalPages;
        } else if (page <= 1) {
            this.currentPage = 1;
        } else {
            this.currentPage = page;
        }

        // now work out where the sub-list should start and end
        startingIndex = pageSize * (currentPage -1);
        if (startingIndex < 0) {
            startingIndex = 0;
        }
        endingIndex = startingIndex + pageSize;
        if (endingIndex > list.size()) {
            endingIndex = list.size();
        }
    }
1331898
public function addPageFilter(Page $page)
    {
        if ($page && !$page->isRoot()) {
            $this->leftJoin('cc._mainnode', 'p')
                    ->leftJoin('p._section', 'sp')
                    ->andWhere('sp._root = :selectedPageRoot')
                    ->andWhere('sp._leftnode >= :selectedPageLeftnode')
                    ->andWhere('sp._rightnode <= :selectedPageRightnode')
                    ->setParameters([
                        'selectedPageRoot' => $page->getSection()->getRoot(),
                        'selectedPageLeftnode' => $page->getLeftnode(),
                        'selectedPageRightnode' => $page->getRightnode(),
                    ]);
        }
    }
827557
protected function handleDelete(Request $request, AbstractPage $page)
    {
        $em = $this->getDoctrine()->getManager();

        $em->remove($page);
        $em->flush();

        return $this->redirect($this->getRedirectUrl($request));
    }
19547
public function resetContent(PageInterface $page, LayoutBlock $layoutBlock, \JMS\Serializer\SerializerInterface $serializer)
    {
	    if ($contentObject = $layoutBlock->getSnapshotContent()) {
		    $contentObject = $serializer->deserialize($contentObject, $layoutBlock->getClassType(), 'json');



		    try {
			    $contentObject = $this->_em->merge($contentObject);
			    $reflection = new \ReflectionClass($contentObject);
			    foreach ($reflection->getProperties() as $property) {
				    $method = sprintf('get%s', ucfirst($property->getName()));
				    if ($reflection->hasMethod($method) && $var = $contentObject->{$method}()) {
					    if ($var instanceof ArrayCollection) {
						    foreach ($var as $key =>  $v) {
							    $v = $this->_em->merge($v);

							    $var->set($key, $v);
						    }
						    $method = sprintf('set%s', ucfirst($property->getName()));
						    $contentObject->{$method}($var);
					    }

					    if(is_object($var) && $this->_em->getMetadataFactory()->hasMetadataFor(get_class($var))){
						    $var = $this->_em->merge($var);

						    $method = sprintf('set%s', ucfirst($property->getName()));
						    $contentObject->{$method}($var);
					    }
				    }
			    }

			    $this->_em->persist($contentObject);
			    $this->_em->flush($contentObject);

		    } catch (EntityNotFoundException $e) {
			    $classType = $layoutBlock->getClassType();
			    $newContentObject = clone $contentObject;
			    $reflection = new \ReflectionClass($contentObject);
			    foreach ($reflection->getProperties() as $property) {
				    $method = sprintf('get%s', ucfirst($property->getName()));
				    if ($reflection->hasMethod($method) && $var = $contentObject->{$method}()) {
					    if ($var instanceof ArrayCollection) {
						    foreach ($var as $key =>  $v) {
							    $v = $this->_em->merge($v);

							    $var->set($key, $v);
						    }
						    $method = sprintf('set%s', ucfirst($property->getName()));
						    $newContentObject->{$method}($var);
					    }

					    if(is_object($var) && $this->_em->getMetadataFactory()->hasMetadataFor(get_class($var))){
						    $var = $this->_em->merge($var);

						    $method = sprintf('set%s', ucfirst($property->getName()));
						    $newContentObject->{$method}($var);
					    }

				    }
			    }
			    $this->_em->persist($newContentObject);
			    $this->_em->flush($newContentObject);


			    $layoutBlock->setObjectId($newContentObject->getId());
		    }

	    }

	    $layoutBlock->setPage($page);

	    $this->_em->persist($layoutBlock);

	    $this->_em->flush($layoutBlock);

	    return $layoutBlock;
    }
292262
public function replaceOptContentTable(AbstractClassContent $content)
    {
        if (null === $content->getMainNode()) {
            return $this;
        }

        $command = 'REPLACE';
        if (!$this->replaceSupported) {
            // REPLACE command not supported, remove first then insert
            $this->removeOptContentTable($content);
            $command = 'INSERT';
        }

        $meta = $this->_em->getClassMetadata('BackBee\ClassContent\Indexes\OptContentByModified');
        $query = $command.' INTO '.$meta->getTableName().
                ' ('.$meta->getColumnName('_uid').', '.
                $meta->getColumnName('_label').', '.
                $meta->getColumnName('_classname').', '.
                $meta->getColumnName('_node_uid').', '.
                $meta->getColumnName('_modified').', '.
                $meta->getColumnName('_created').')'.
                ' VALUES (:uid, :label, :classname, :node_uid, :modified, :created)';

        $params = array(
            'uid' => $content->getUid(),
            'label' => $content->getLabel(),
            'classname' => AbstractClassContent::getShortClassname($content),
            'node_uid' => $content->getMainNode()->getUid(),
            'modified' => date('Y-m-d H:i:s', $content->getModified()->getTimestamp()),
            'created' => date('Y-m-d H:i:s', $content->getCreated()->getTimestamp()),
        );

        $types = array(
            \Doctrine\DBAL\Connection::PARAM_STR_ARRAY,
            \Doctrine\DBAL\Connection::PARAM_STR_ARRAY,
            \Doctrine\DBAL\Connection::PARAM_STR_ARRAY,
            \Doctrine\DBAL\Connection::PARAM_STR_ARRAY,
            \Doctrine\DBAL\Connection::PARAM_STR_ARRAY,
            \Doctrine\DBAL\Connection::PARAM_STR_ARRAY,
        );

        return $this->executeUpdate($query, $params, $types);
    }
1359510
private function updateElements(AbstractClassContent $content, array $elementsData)
    {
        if ($content instanceof ContentSet) {
            $elements = $this->prepareElements($elementsData, false);
            $page = $this->isMainZone($content);
            $this->updateContentSetElements($content, $elements, $page);
        } else {
            $elements = $this->prepareElements($elementsData);
            $this->updateContentElements($content, $elements);
        }

        return $this;
    }
224392
private function autoCommitContent(AbstractClassContent $content)
    {
        // Commit subelement of the Media content
        foreach ($content->getData() as $subcontent) {
            if (!($subcontent instanceof AbstractClassContent)) {
                continue;
            }

            $this->commit($subcontent);
        }

        // Commit the Media content itself
        $this->commit($content);
    }