@param Request                $request
@param bool                   $preview
@param EntityManagerInterface $em
@param NodeTranslation        $nodeTranslation

@return \Kunstmaan\NodeBundle\Entity\HasNodeInterface
176512
private function getPageEntity(Request $request, $preview, EntityManagerInterface $em, NodeTranslation $nodeTranslation)
    {
        /* @var HasNodeInterface $entity */
        $entity = null;
        if ($preview) {
            $version = $request->get('version');
            if (!empty($version) && is_numeric($version)) {
                $nodeVersion = $em->getRepository('KunstmaanNodeBundle:NodeVersion')->find($version);
                if (!is_null($nodeVersion)) {
                    $entity = $nodeVersion->getRef($em);
                }
            }
        }
        if (is_null($entity)) {
            $entity = $nodeTranslation->getPublicNodeVersion()->getRef($em);

            return $entity;
        }

        return $entity;
    }
1277708
public function imageAction(Request $request)
    {
        $params = $request->request->all();

        unset($params['module']);
        unset($params['controller']);
        unset($params['action']);

        if (empty($params['width'])) {
            $params['width'] = 100;
        }
        if (empty($params['height'])) {
            $params['height'] = 100;
        }
        if (empty($params['xmethod'])) {
            $params['xmethod'] = 'fit';
        }

        $previewer = $this->get('phlexible_media_template.previewer.image');
        $locator = $this->get('file_locator');

        $previewImage = 'test_1000_600.jpg';
        if (isset($params['preview_image'])) {
            $previewImage = $params['preview_image'];
            unset($params['preview_image']);
            if ($previewImage === '800_600') {
                $previewImage = "test_$previewImage.png";
            } else {
                $previewImage = "test_$previewImage.jpg";
            }
        }

        $filePath = $locator->locate("@PhlexibleMediaTemplateBundle/Resources/public/images/$previewImage", null, true);
        $data = $previewer->create($filePath, $params);

        return new ResultResponse(true, 'Preview created', $data);
    }
911794
public function preview($entity, $id)
    {
        $modelString = 'Grafite\Cms\Models\\'.ucfirst($entity);

        if (!class_exists($modelString)) {
            $modelString = 'Grafite\Cms\Models\\'.ucfirst($entity).'s';
        }

        $model = new $modelString();
        $modelInstance = $model->find($id);

        $data = [
            $entity => $modelInstance,
        ];

        if (config('app.locale') != config('cms.default-language', Cms::config('cms.default-language'))) {
            if ($modelInstance->translation(config('app.locale'))) {
                $data = [
                    $entity => $modelInstance->translation(config('app.locale'))->data,
                ];
            }
        }

        $view = 'cms-frontend::'.$entity.'.show';

        if (!View::exists($view)) {
            $view = 'cms-frontend::'.$entity.'s.show';
        }

        if ($entity === 'page') {
            $view = 'cms-frontend::pages.'.$modelInstance->template;
        }

        if ($entity === 'blog') {
            $view = 'cms-frontend::blog.'.$modelInstance->template;
        }

        return view($view, $data);
    }
176388
protected function addPageContent(NodeTranslation $nodeTranslation, $page, &$doc)
    {
        $this->enterRequestScope($nodeTranslation->getLang());
        if ($this->logger) {
            $this->logger->debug(
                sprintf(
                    'Indexing page "%s" / lang : %s / type : %s / id : %d / node id : %d',
                    $page->getTitle(),
                    $nodeTranslation->getLang(),
                    get_class($page),
                    $page->getId(),
                    $nodeTranslation->getNode()->getId()
                )
            );
        }

        $renderer = $this->container->get('templating');
        $doc['content'] = '';

        if ($page instanceof SearchViewTemplateInterface) {
            $doc['content'] = $this->renderCustomSearchView($nodeTranslation, $page, $renderer);

            return null;
        }

        if ($page instanceof HasPagePartsInterface) {
            $doc['content'] = $this->renderDefaultSearchView($nodeTranslation, $page, $renderer);

            return null;
        }
    }
1265745
public function createPageDraftFromOtherLanguage(Node $node, $sourceNodeTranslationId, $locale)
    {
        $user = $this->getAdminUser();

        $sourceNodeTranslation = $this->em->getRepository(NodeTranslation::class)->find($sourceNodeTranslationId);
        $sourceNodeVersion = $sourceNodeTranslation->getPublicNodeVersion();
        $sourcePage = $sourceNodeVersion->getRef($this->em);
        $targetPage = $this->cloneHelper->deepCloneAndSave($sourcePage);

        /* @var NodeTranslation $nodeTranslation */
        $nodeTranslation = $this->em->getRepository(NodeTranslation::class)->addDraftNodeVersionFor($targetPage, $locale, $node, $user);
        $nodeVersion = $nodeTranslation->getPublicNodeVersion();

        $this->eventDispatcher->dispatch(
            Events::RECOPY_PAGE_TRANSLATION,
            new RecopyPageTranslationNodeEvent(
                $node,
                $nodeTranslation,
                $nodeVersion,
                $targetPage,
                $sourceNodeTranslation,
                $sourceNodeVersion,
                $sourcePage,
                $sourceNodeTranslation->getLang()
            )
        );

        return $nodeTranslation;
    }
127244
public function importPreviewAction(Request $request, User $loggedUser, $format, $previewId)
    {
        $this->checkPortfolioToolAccess();

        $temporaryImportFilePathToSearch = sprintf('%s-%s.%s.import', strtolower($loggedUser->getUsername()), $previewId, $format);

        $finder = new Finder();
        $files = $finder->files()->in($this->container->get('claroline.config.platform_config_handler')->getParameter('tmp_dir'))
            ->depth('0')->name($temporaryImportFilePathToSearch);
        $filesCount = $files->count();
        $errorMessage = null;

        if (0 === $filesCount) {
            $errorMessage = 'portfolio_import_error_import_file_not_found_message';
        } elseif (1 < $filesCount) {
            $errorMessage = 'portfolio_import_error_import_too_many_file_message';
        }

        if (null !== $errorMessage) {
            $this->getSessionFlashbag()->add('error', $this->getTranslator()->trans($errorMessage, [], 'icap_portfolio'));

            return $this->redirect($this->generateUrl('icap_portfolio_import', ['format' => $format]));
        }

        if ($request->isMethod('POST')) {
            try {
                foreach ($files as $file) {
                    $importManager = $this->getImportManager();

                    $portfolio = $importManager->doImport($file->getContents(), $loggedUser, $format);
                }

                if ($request->isXmlHttpRequest()) {
                    return new JsonResponse([]);
                } else {
                    $this->getSessionFlashbag()
                        ->add('success', $this->getTranslator()
                            ->trans('portfolio_import_success_message', [], 'icap_portfolio'));

                    return $this->redirect($this->generateUrl('icap_portfolio_index'));
                }
            } catch (\Exception $exception) {
                $this->getSessionFlashbag()
                    ->add('error', $this->getTranslator()
                        ->trans('portfolio_import_error_message', [], 'icap_portfolio'));

                throw $exception;
            }
        }

        foreach ($files as $file) {
            $portfolio = $this->getImportManager()->simulateImport($file->getContents(), $loggedUser, $format);
        }

        return [
            'format' => $format,
            'previewId' => $previewId,
            'portfolio' => $portfolio,
        ];
    }
1081471
public function childelementsAction(Request $request)
    {
        $id = $request->get('id');
        $language = $request->get('language');

        $treeManager = $this->get('phlexible_tree.tree_manager');
        $elementService = $this->get('phlexible_element.element_service');
        $iconResolver = $this->get('phlexible_element.icon_resolver');

        $tree = $treeManager->getByNodeID($id);
        $node = $tree->get($id);
        $eid = $node->getTypeId();
        $element = $elementService->findElement($eid);

        if (!$language) {
            $language = $element->getMasterLanguage();
        }

        $firstString = $this->get('translator')->trans('elements.first', [], 'gui');

        $data = [];
        $data[] = [
            'id' => '0',
            'title' => $firstString,
            'icon' => $iconResolver->resolveIcon('_top.gif'),
        ];

        foreach ($tree->getChildren($node) as $childNode) {
            $childElement = $elementService->findElement($childNode->getTypeId());
            $childElementVersion = $elementService->findLatestElementVersion($childElement);

            $data[] = [
                'id' => $childNode->getId(),
                'title' => $childElementVersion->getBackendTitle($language, $childElementVersion->getElement()->getMasterLanguage()).' ['.$childNode->getId().']',
                'icon' => $iconResolver->resolveTreeNode($childNode, $language),
            ];
        }

        return new JsonResponse(['elements' => $data]);
    }
506837
public function selectNodesLazy(Request $request)
    {
        /* @var EntityManagerInterface $em */
        $em = $this->getDoctrine()->getManager();
        $locale = $request->getLocale();
        $id = $request->query->get('id');
        $depth = $this->getParameter('kunstmaan_node.url_chooser.lazy_increment');

        if (!$id || $id == '#') {
            $domainConfig = $this->get('kunstmaan_admin.domain_configuration');

            if ($domainConfig->isMultiDomainHost()) {
                $switchedHost = $domainConfig->getHostSwitched();
                $rootItems = [$domainConfig->getRootNode($switchedHost['host'])];
            } else {
                $rootItems = $em->getRepository('KunstmaanNodeBundle:Node')->getAllTopNodes();
            }
        } else {
            $rootItems = $em->getRepository('KunstmaanNodeBundle:Node')->find($id)->getChildren();
        }

        $results = $this->nodesToArray($locale, $rootItems, $depth);

        return new JsonResponse($results);
    }
181439
public function previewAction(Request $request, $id)
    {
        $em = $this->getDoctrine()->getManager();

        $entity = $em->getRepository('VeonikBlogBundle:Post')->find($id);

        if (!$entity) {
            throw $this->createNotFoundException('Unable to find Post entity.');
        }

        $request->attributes->set('slug', $entity->getSlug());

        return array(
            'entities'      => array($entity),
        );
    }
1212225
public function referenceAction(Request $request)
    {
        $siterootId = $request->get('siteroot_id');
        $tid = $request->get('node');
        $language = $request->get('language');

        $treeManager = $this->get('phlexible_tree.tree_manager');
        $elementService = $this->get('phlexible_element.element_service');
        $translator = $this->get('translator');
        $teaserManager = $this->get('phlexible_teaser.teaser_manager');
        $elementSourceManager = $this->get('phlexible_element.element_source_manager');
        $nodeSerializer = $this->get('phlexible_tree.node_serializer');
        $iconResolver = $this->get('phlexible_element.icon_resolver');

        $tree = $treeManager->getBySiteRootId($siterootId);

        $treeNode = $tree->get($tid);
        $rootNode = $tree->getRoot();

        $data = [];
        if ($rootNode !== null) {
            if ($tid === null || $tid < 1) {
                $data = [$nodeSerializer->serializeNode($rootNode, $language)];

                return new JsonResponse($data);
            }

            $node = $tree->get($tid);

            // check if children of this node should be shown
            $element = $elementService->findElement($node->getTypeId());
            $elementtype = $elementService->findElementtype($element);

            $nodes = $tree->getChildren($node);
            if (!empty($nodes) && !$elementtype->getHideChildren()) {
                $data = $nodeSerializer->serializeNodes($nodes, $language);
            }

            foreach ($data as $key => $row) {
                if ($row['leaf']) {
                    unset($data[$key]);
                    continue;
                }
                $data[$key]['cls'] = (!empty($data[$key]['cls']) ? $data[$key]['cls'].' ' : '').'node-disabled';
            }
        }

        $currentTreeId = $tid;

        $element = $elementService->findElement($treeNode->getTypeId());
        $elementtype = $elementService->findElementtype($element);

        $layoutareas = [];
        // TODO: repair
        foreach ($elementSourceManager->findElementtypesByType('layout') as $layoutarea) {
            if (in_array($elementtype, $elementService->findAllowedParents($layoutarea))) {
                $layoutareas[] = $layoutarea;
            }
        }

        foreach ($layoutareas as $layoutarea) {
            $areaRoot = [
                'id' => 'area_'.$layoutarea->getId(),
                'area_id' => $layoutarea->getId(),
                'parent_tid' => $currentTreeId,
                'parent_eid' => $element->getEid(),
                'icon' => $iconResolver->resolveElementtype($layoutarea),
                'text' => $layoutarea->getTitle(),
                'type' => 'area',
                'inherited' => null, //true,
                'leaf' => false,
                'expanded' => true,
                'allowDrag' => false,
                'allowDrop' => false,
                'children' => [],
                'qtip' => $translator->trans('elements.doubleclick_to_sort', [], 'gui'),
            ];

            $teasers = $teaserManager->findForLayoutAreaAndTreeNode($layoutarea, $treeNode);

            foreach ($teasers as $teaser) {
                switch ($teaser->getType()) {
                    case 'element':
                        $teaserElement = $elementService->findElement($teaser->getTypeId());
                        $teaserElementVersion = $elementService->findLatestElementVersion($teaserElement);

                        $areaRoot['children'][] = [
                            'id' => $teaser->getId(),
                            'parent_tid' => $currentTreeId,
                            'parent_eid' => $element->getEid(),
                            'layoutarea_id' => $layoutarea->getId(),
                            'icon' => $iconResolver->resolveTeaser($teaser, $language),
                            'text' => $teaserElementVersion->getBackendTitle($language),
                            'text' => $teaserElementVersion->getBackendTitle($language),
                            'eid' => $teaser->getTypeId(),
                            'type' => 'teaser',
                            'expanded' => false,
                            'leaf' => true,
                            'allowDrag' => false,
                            'allowDrop' => false,
                            'children' => [],
                        ];

                        break;
                }
            }

            if (count($areaRoot['children'])) {
                $data[] = $areaRoot;
            }
        }

        $data = array_values($data);

        return new JsonResponse($data);
    }
1255000
public function updatePage(
        Node $node,
        NodeTranslation $nodeTranslation,
        NodeVersion $nodeVersion,
        HasNodeInterface $page,
        $isStructureNode,
        TabPane $tabPane = null
    ) {
        $this->eventDispatcher->dispatch(
            Events::PRE_PERSIST,
            new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
        );

        $nodeTranslation->setTitle($page->getTitle());
        if ($isStructureNode) {
            $nodeTranslation->setSlug('');
        }

        $nodeVersion->setUpdated(new \DateTime());
        if ($nodeVersion->getType() == NodeVersion::PUBLIC_VERSION) {
            $nodeTranslation->setUpdated($nodeVersion->getUpdated());
        }
        $this->em->persist($nodeTranslation);
        $this->em->persist($nodeVersion);
        $this->em->persist($node);
        if (null !== $tabPane) {
            $tabPane->persist($this->em);
        }
        $this->em->flush();

        $this->eventDispatcher->dispatch(
            Events::POST_PERSIST,
            new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
        );

        return $nodeTranslation;
    }
1214469
public function inheritAction(Request $request)
    {
        $treeId = (int) $request->get('tree_id');
        $teaserId = (int) $request->get('teaser_id');

        $dispatcher = $this->get('event_dispatcher');
        $teaserManager = $this->get('phlexible_teaser.teaser_manager');

        $teaser = $teaserManager->find($teaserId);
        $teaser->removeStopId($treeId);

        $event = new TeaserEvent($teaser);
        if ($dispatcher->dispatch(TeaserEvents::BEFORE_INHERIT_TEASER, $event)->isPropagationStopped()) {
            throw new RuntimeException('Inherit cancelled by event');
        }

        $teaserManager->updateTeaser($teaser);

        $event = new TeaserEvent($teaser);
        $dispatcher->dispatch(TeaserEvents::INHERIT_TEASER, $event);

        return new ResultResponse(true, 'Inheritance stop removed');
    }
657187
public function render(Request $request, Exception $e)
    {
        $e = $this->prepareException($e);

        if ($e instanceof HttpResponseException) {
            return $e->getResponse();
        } else if ($e instanceof AuthenticationException) {
            return $this->unauthenticated($request, $e);
        } else if ($e instanceof ValidationException) {
            return $this->convertValidationExceptionToResponse($e, $request);
        }

        return $this->prepareResponse($request, $e);
    }
688612
public function editAction(Request $request, $id = null)
    {
        $this->denyAccessUnlessGranted('ROLE_ADMIN');

        $em = $this->getDoctrine()->getManager();

        if (is_numeric($id)) {
            $locale = $em->getRepository(Locale::class)->find($id);
        } else {
            $locale = $em->getRepository(Locale::class)->findOneByLocale($id);
        }

        $form = $this->createForm(new LocaleType(), $locale);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em->persist($locale);
            $em->flush();

            $this->addFlash('success', 'Locale has been updated successfully');

            return $this->redirectToRoute('opifer_cms_locale_edit', ['id' => $locale->getId()]);
        }

        return $this->render('OpiferCmsBundle:Backend/Locale:edit.html.twig', [
            'locale' => $locale,
            'form' => $form->createView()
        ]);
    }
227346
public function showAction(
        Request $request,
        FlattenException $exception,
        DebugLoggerInterface $logger = null
    ) {
        $code = $exception->getStatusCode();
        $template = null;
        if ($webspace = $this->requestAnalyzer->getWebspace()) {
            $template = $webspace->getTemplate('error-' . $code, $request->getRequestFormat());

            if (null === $template) {
                $template = $webspace->getTemplate('error', $request->getRequestFormat());
            }
        }

        $showException = $request->attributes->get('showException', $this->debug);
        if ($showException || null === $template || !$this->twig->getLoader()->exists($template)) {
            return $this->exceptionController->showAction($request, $exception, $logger);
        }

        $context = $this->parameterResolver->resolve(
            [
                'status_code' => $code,
                'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '',
                'exception' => $exception,
                'currentContent' => $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1)),
            ],
            $this->requestAnalyzer
        );

        return new Response(
            $this->twig->render(
                $template,
                $context
            ),
            $code
        );
    }
396084
public function publishAction(Request $request)
    {
        $tid = $request->get('tid');
        $teaserId = $request->get('teaser_id', null);
        $version = $request->get('version', null);
        $language = $request->get('language');
        $comment = $request->get('comment', '');

        //$fileUsage = new Makeweb_Elements_Element_FileUsage(MWF_Registry::getContainer()->dbPool);

        if (!$teaserId) {
            $treeManager = $this->get('phlexible_tree.tree_manager');
            $tree = $treeManager->getByNodeId($tid);
            $node = $tree->get($tid);

            $tree->publish($node, $version, $language, $this->getUser()->getId(), $comment);

            #$eid = $node->getEid();
            //$fileUsage->update($node->getEid());

            $data = [];

            #$elementVersionManager = Makeweb_Elements_Element_Version_Manager::getInstance();
            #$elementVersion = $elementVersionManager->get($node->getEid(), $version);

            $data['status'] = $tree->isAsync($node, $language) ? 'async' : ($tree->isPublished($node, $language) ? 'online' : null);
            $data['instance'] = ($tree->isInstance($node) ? ($tree->isInstanceMaster($node) ? 'master' : 'slave') : false);
            #$data['icon'] = $elementVersion->getIconUrl($node->getIconParams($language));

            $response = new ResultResponse(true, 'TID "'.$tid.'" published.', $data);
        } else {
            $teaserManager = $this->get('phlexible_teaser.teaser_manager');
            $teaser = $teaserManager->find($teaserId);

            $eid = $teaserManager->publishTeaser($teaser, $version, $language, $this->getUser()->getId(), $comment);

            //$fileUsage->update($eid);

            $response = new ResultResponse(true, "Teaser ID $teaserId published.");
        }

        return $response;
    }
787510
protected function renderException(Request $request, Exception $e)
    {
        return $this->app['Nano7\Foundation\Contracts\Exception\ExceptionHandler']->render($request, $e);
    }