Render action.

@param Request $request
@param int     $teaserId

@return Response
@Route("/{_locale}/{teaserId}", name="teaser_render")
545451
public function htmlAction(Request $request, $teaserId)
    {
        $requestStack = $this->get('request_stack');
        $masterRequest = $requestStack->getMasterRequest();

        if ($request->get('preview') || $request->get('_preview')) {
            $request->attributes->set('_preview', true);
        } elseif ($masterRequest !== $request && $masterRequest->attributes->get('_preview')) {
            $request->attributes->set('_preview', true);
        }

        $teaser = $this->get('phlexible_teaser.teaser_service')->find($teaserId);

        $request->attributes->set('contentDocument', $teaser);

        $renderConfigurator = $this->get('phlexible_element_renderer.configurator');
        $renderConfig = $renderConfigurator->configure($request);

        if ($renderConfig->getResponse()) {
            return $renderConfig->getResponse();
        }

        if ($request->get('template')) {
            $renderConfig->set('template', $request->get('template', 'teaser'));
        }

        $data = $renderConfig->getVariables();

        return $this->render($data['template'], (array) $data);
    }
862863
public function previewAction(Request $request, DataInterface $data)
    {
        return $this->editAction($request, $data, $data->getFamily());
    }
379573
public function createEmptyPageAction(Request $request, $id)
    {
        $this->init($request);
        /* @var Node $node */
        $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id);

        $this->denyAccessUnlessGranted(PermissionMap::PERMISSION_EDIT, $node);

        $entityName = $node->getRefEntityName();
        /* @var HasNodeInterface $myLanguagePage */
        $myLanguagePage = new $entityName();
        $myLanguagePage->setTitle('New page');

        $this->em->persist($myLanguagePage);
        $this->em->flush();
        /* @var NodeTranslation $nodeTranslation */
        $nodeTranslation = $this->em->getRepository('KunstmaanNodeBundle:NodeTranslation')
            ->createNodeTranslationFor($myLanguagePage, $this->locale, $node, $this->user);
        $nodeVersion = $nodeTranslation->getPublicNodeVersion();

        $this->get('event_dispatcher')->dispatch(
            Events::ADD_EMPTY_PAGE_TRANSLATION,
            new NodeEvent($node, $nodeTranslation, $nodeVersion, $myLanguagePage)
        );

        return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', array('id' => $id)));
    }
415412
public function renderAction(Request $request)
    {
        /*
        $this->admin->checkAccess('compose');
        if (false === $this->get('sonata.dashboard.admin.block')->isGranted('LIST')) {
            throw $this->createAccessDeniedException();
        }
        */

        $admin = $this->getAdmin();

        $id = $request->get($admin->getIdParameter());

        $dashboard = $admin->getObject($id);

        if (!$dashboard) {
            throw $this->createNotFoundException(sprintf('unable to find the dashboard with id : %s', $id));
        }

        $containers = [];

        /** @var array $blocks */
        $blocks = $dashboard->getBlocks();

        // separate containers.
        foreach ($blocks as $block) {
            $containers[] = $block;
        }

        return $this->renderWithExtraParams('@CompoSonataDashboard/Dashboard/render.html.twig', [
            'action' => 'render',
            'admin' => $admin,
            'object' => $dashboard,

            'dashboard' => $dashboard,
            'containers' => $containers,
        ]);
    }
1025884
public function showAction(Request $request, $id)
    {
        $this->checkIfUserHasPermission(Permission::VIEW);

        list($parentEntity) = $this->getParentEntityDefinition($request);

        $entity = $this->getEntity($id);

        $this->getEventDispatcher()->dispatch(
            Events::PRE_CRUD_CONTROLLER_ACTION,
            new CrudControllerActionEvent($this->meta, __FUNCTION__)
        );

        try {
            $this->getCustomObjectLoader()->loadCustomObjects($entity);
        } catch (CustomObjectException $ex) {
        }

        $view = $this->getEntityToShowViewTransformer()->transform($this->meta, $entity);

        return $this->renderResponse('show', [
            'entity'        => $entity,
            'meta'          => $this->meta,
            'parent_entity' => $parentEntity,
            'view'          => $view,
        ], $request->isXmlHttpRequest());
    }
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);
    }
658429
public function postGenerateAction(Request $request)
    {
        $parentUuid = $this->getRequestParameter($request, 'parent');
        $parts = $this->getRequestParameter($request, 'parts', true);
        $templateKey = $this->getRequestParameter($request, 'template', true);
        $webspaceKey = $this->getRequestParameter($request, 'webspace', true);
        $languageCode = $this->getLocale($request);

        $result = $this->getResourceLocatorRepository()->generate(
            $parts,
            $parentUuid,
            $webspaceKey,
            $languageCode,
            $templateKey
        );

        return $this->handleView($this->view($result));
    }
293697
public function slugAction(Request $request, $url = null, $preview = false)
    {
        /* @var EntityManager $em */
        $em = $this->getDoctrine()->getManager();
        $locale = $request->getLocale();

        /* @var NodeTranslation $nodeTranslation */
        $nodeTranslation = $request->attributes->get('_nodeTranslation');

        // If no node translation -> 404
        if (!$nodeTranslation) {
            throw $this->createNotFoundException('No page found for slug ' . $url);
        }

        $entity = $this->getPageEntity(
            $request,
            $preview,
            $em,
            $nodeTranslation
        );
        $node = $nodeTranslation->getNode();

        $securityEvent = new SlugSecurityEvent();
        $securityEvent
            ->setNode($node)
            ->setEntity($entity)
            ->setRequest($request)
            ->setNodeTranslation($nodeTranslation);

        $nodeMenu = $this->container->get('kunstmaan_node.node_menu');
        $nodeMenu->setLocale($locale);
        $nodeMenu->setCurrentNode($node);
        $nodeMenu->setIncludeOffline($preview);

        $eventDispatcher = $this->get('event_dispatcher');
        $eventDispatcher->dispatch(Events::SLUG_SECURITY, $securityEvent);

        //render page
        $renderContext = new RenderContext(
            array(
                'nodetranslation' => $nodeTranslation,
                'slug' => $url,
                'page' => $entity,
                'resource' => $entity,
                'nodemenu' => $nodeMenu,
            )
        );
        if (method_exists($entity, 'getDefaultView')) {
            /* @noinspection PhpUndefinedMethodInspection */
            $renderContext->setView($entity->getDefaultView());
        }
        $preEvent = new SlugEvent(null, $renderContext);
        $eventDispatcher->dispatch(Events::PRE_SLUG_ACTION, $preEvent);
        $renderContext = $preEvent->getRenderContext();

        /** @noinspection PhpUndefinedMethodInspection */
        $response = $entity->service($this->container, $request, $renderContext);

        $postEvent = new SlugEvent($response, $renderContext);
        $eventDispatcher->dispatch(Events::POST_SLUG_ACTION, $postEvent);

        $response = $postEvent->getResponse();
        $renderContext = $postEvent->getRenderContext();

        if ($response instanceof Response) {
            return $response;
        }

        $view = $renderContext->getView();
        if (empty($view)) {
            throw $this->createNotFoundException(sprintf('Missing view path for page "%s"', get_class($entity)));
        }

        $template = new Template(array());
        $template->setTemplate($view);

        $request->attributes->set('_template', $template);

        return $renderContext->getArrayCopy();
    }
1002818
public function send(?Request $request = null) {
        $request = self::validateRequest($request);

        $this->
            render($request)->
            prepare($request)->
            send();
    }
741662
public function renderTemplate($templateId, $request)
    {
        $query = ($request instanceof Request) ? $request->id : $request;
        return $this->sendRequest('GET', '/templates/' . $templateId . '/render?request_id=' . $query);
    }
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),
        );
    }
1043688
public function urlsAction(Request $request)
    {
        $tid = $request->get('tid');
        $language = $request->get('language');

        $treeManager = $this->get('phlexible_tree.tree_manager');
        $stateManager = $this->get('phlexible_tree.state_manager');

        $node = $treeManager->getByNodeId($tid)->get($tid);

        $urls = [
            'preview' => '',
            'online' => '',
        ];

        if ($node) {
            $nodeUrlGenerator = $this->get('phlexible_tree.node_url_generator');
            $urls['preview'] = $nodeUrlGenerator->generatePreviewUrl($node, $language);

            if ($stateManager->isPublished($node, $language)) {
                try {
                    $urls['online'] = $nodeUrlGenerator->generateOnlineUrl($node, $language);
                } catch (\Exception $e) {
                }
            }
        }

        return new ResultResponse(true, '', $urls);
    }
1145036
public function render(Request $request, array $options = array())
    {
        return $this->doRender(
            $options + array(
                'shortname' => $this->shortName,
                'identifier' => $request->getPathInfo(),
                'count' => $this->count,
            )
        );
    }
311752
public function getAction(Request $request, $id)
    {
        $locale = $this->getRequestParameter($request, 'locale', true);
        $view = $this->responseGetById(
            $id,
            function($id) use ($locale) {
                return $this->getManager()->findByIdAndLocale($id, $locale);
            }
        );

        return $this->handleView($view);
    }
1301656
public function sitemapPaginatedAction(Request $request, $alias, $page)
    {
        if (null !== ($response = $this->getDumpedSitemapResponse($request, $alias, $page))) {
            return $response;
        }

        $portal = $request->get('_sulu')->getAttribute('portal');
        $localization = $request->get('_sulu')->getAttribute('localization');
        if (!$localization) {
            $localization = $portal->getXDefaultLocalization();
        }

        $sitemap = $this->get('sulu_website.sitemap.xml_renderer')->renderSitemap(
            $alias,
            $page,
            $localization->getLocale(),
            $portal,
            $request->getHttpHost(),
            $request->getScheme()
        );

        if (!$sitemap) {
            return new Response(null, 404);
        }

        return $this->setCacheLifetime(new Response($sitemap));
    }
252100
private function createContentTeaserFromTeaser(Teaser $teaser)
    {
        if (!isset($this->contentTeasers[$teaser->getId()])) {
            $contentTeaser = new ContentTeaser();
            $contentTeaser
                ->setId($teaser->getId())
                ->setLayoutareaId($teaser->getLayoutareaId())
                ->setTreeId($teaser->getTreeId())
                ->setEid($teaser->getEid())
                ->setTypeId($teaser->getTypeId())
                ->setType($teaser->getType())
                ->setSort($teaser->getSort())
                ->setCache($teaser->getCache())
                ->setAttributes($teaser->getAttributes())
                ->setCreatedAt($teaser->getCreatedAt())
                ->setCreateUserId($teaser->getCreateUserId());

            $contentTeaser->setTitle($this->mediator->getTitle($teaser, 'navigation', $this->language));
            $contentTeaser->setUniqueId($this->mediator->getUniqueId($teaser));

            $this->contentTeasers[$teaser->getId()] = $contentTeaser;
        }

        return $this->contentTeasers[$teaser->getId()];
    }
1038466
public function treeAction(Request $request)
    {
        $language = $request->get('language');
        $treeId = (int) $request->get('tid');

        if (!$treeId || !$language) {
            return new Response('', 500);
        }

        $translator = $this->get('translator');
        $treeManager = $this->get('phlexible_tree.tree_manager');
        $teaserService = $this->get('phlexible_teaser.teaser_service');
        $elementService = $this->get('phlexible_element.element_service');
        $elementSourceManager = $this->get('phlexible_element.element_source_manager');
        $iconResolver = $this->get('phlexible_element.icon_resolver');

        $tree = $treeManager->getByNodeId($treeId);
        $treeNode = $tree->get($treeId);
        $element = $elementService->findElement($treeNode->getTypeId());
        $elementMasterLanguage = $element->getMasterLanguage();
        $elementtype = $elementService->findElementtype($element);

        $treeNodePath = $tree->getPath($treeNode);

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

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

            foreach ($teasers as $teaser) {
                /* @var $teaser Teaser */
                $teaserData = [
                    'id' => $teaser->getId(),
                    'layoutarea_id' => $layoutarea->getId(),
                    'parent_tid' => $treeId,
                    'parent_eid' => $element->getEid(),
                    'type' => $teaser->getType(),
                    'sort' => $teaser->getInheritSort($treeId),
                    'inherited' => false,
                    'inherit' => false,
                    'leaf' => true,
                    'hide' => false,
                    'expanded' => false,
                    'cls' => '',
                    'children' => [],
                    'allowDrag' => false,
                    'allowDrop' => false,
                ];

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

                        $cls = '';
                        if (!$teaser->isStopped()) {
                            $cls .= 'inherit ';
                        }
                        if ($teaser->isHidden()) {
                            $cls .= 'dont-show ';
                        }
                        if ($teaser->getTreeId() !== $treeId) {
                            $cls .= 'inherited ';
                        }

                        $teaserData = array_merge(
                            $teaserData,
                            [
                                'text' => $teaserElementVersion->getBackendTitle($language),
                                'icon' => $iconResolver->resolveTeaser($teaser, $language),
                                'eid' => $teaserElement->getEid(),
                                'inherited' => $teaser->getTreeId() !== $treeId,
                                'inherit' => !$teaser->isStopped(),
                                'cls' => trim($cls),
                                'hide' => $teaser->isHidden(),
                            ]
                        );
                        break;

                    default:
                        continue;
                }

                $areaRoot['children'][] = $teaserData;
            }

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

            $layouts[] = $areaRoot;
        }

        return new JsonResponse($layouts);
    }