public function preview(Request $request, $contenttypeslug)
    {
        if (!$request->isMethod('POST')) {
            throw new MethodNotAllowedHttpException(['POST'], 'This route only accepts POST requests.');
        }

        $contenttype = $this->getContentType($contenttypeslug);
        $formValues = $request->request->all();

        $storage = $this->storage();
        if ($storage instanceof EntityManager) {
            /** @var EntityManager $storage */
            /** @var Content $content */
            $content = $storage->create($contenttypeslug, $formValues);

            /** @var Collection\Relations $related */
            $related = $storage->createCollection(Relations::class);
            $related->setFromPost($formValues, $content);
            $content->setRelation($related);

            /** @var Collection\Taxonomy $taxonomies */
            $taxonomies = $storage->createCollection(Taxonomy::class);
            $taxonomies->setFromPost($formValues, $content);
            $content->setTaxonomy($taxonomies);

        } else {
            $content = $storage->getContentObject($contenttypeslug, [], false);
            $content->setFromPost($formValues, $contenttype);
        }

        $this->fixBlockFieldsForPreview($content);
        $this->fixHTMLFieldsForPreview($content);

        $liveEditor = $request->get('_live-editor-preview');
        if (!empty($liveEditor)) {
            $jsFile = (new JavaScript('js/ckeditor/ckeditor.js', 'bolt'))
                ->setPriority(1)
                ->setLate(false);
            $cssFile = (new Stylesheet('css/liveeditor.css', 'bolt'))
                ->setPriority(5)
                ->setLate(false);
            $snippet = (new Snippet())
                ->setCallback('<script>window.boltIsEditing = true;</script>')
                ->setLocation(Target::BEFORE_HEAD_JS);

            $this->app['asset.queue.snippet']->add($snippet);
            $this->app['asset.queue.file']->add($jsFile);
            $this->app['asset.queue.file']->add($cssFile);
        }

        // Then, select which template to use, based on our 'cascading templates rules'
        $template = $this->templateChooser()->record($content);

        // Make sure we can also access it as {{ page.title }} for pages, etc. We set these in the global scope,
        // So that they're also available in menu's and templates rendered by extensions.
        $globals = [
            'record'                      => $content,
            $contenttype['singular_slug'] => $content,
        ];

        return $this->render($template, [], $globals);
    }
public function preview(Request $request, $contenttypeslug)
    {
        if (!$request->isMethod('POST')) {
            throw new MethodNotAllowedHttpException(['POST'], 'This route only accepts POST requests.');
        }

        $contenttype = $this->getContentType($contenttypeslug);
        $formValues = $request->request->all();

        $storage = $this->storage();
        if ($storage instanceof EntityManager) {
            /** @var EntityManager $storage */
            /** @var Content $content */
            $content = $storage->create($contenttypeslug, $formValues);

            /** @var Collection\Relations $related */
            $related = $storage->createCollection(Relations::class);
            $related->setFromPost($formValues, $content);
            $content->setRelation($related);

            /** @var Collection\Taxonomy $taxonomies */
            $taxonomies = $storage->createCollection(Taxonomy::class);
            $taxonomies->setFromPost($formValues, $content);
            $content->setTaxonomy($taxonomies);

        } else {
            $content = $storage->getContentObject($contenttypeslug, [], false);
            $content->setFromPost($formValues, $contenttype);
        }

        $this->fixBlockFieldsForPreview($content);
        $this->fixHTMLFieldsForPreview($content);

        $liveEditor = $request->get('_live-editor-preview');
        if (!empty($liveEditor)) {
            $jsFile = (new JavaScript('js/ckeditor/ckeditor.js', 'bolt'))
                ->setPriority(1)
                ->setLate(false);
            $cssFile = (new Stylesheet('css/liveeditor.css', 'bolt'))
                ->setPriority(5)
                ->setLate(false);
            $snippet = (new Snippet())
                ->setCallback('<script>window.boltIsEditing = true;</script>')
                ->setLocation(Target::BEFORE_HEAD_JS);

            $this->app['asset.queue.snippet']->add($snippet);
            $this->app['asset.queue.file']->add($jsFile);
            $this->app['asset.queue.file']->add($cssFile);
        }

        // Then, select which template to use, based on our 'cascading templates rules'
        $template = $this->templateChooser()->record($content);

        // Make sure we can also access it as {{ page.title }} for pages, etc. We set these in the global scope,
        // So that they're also available in menu's and templates rendered by extensions.
        $globals = [
            'record'                      => $content,
            $contenttype['singular_slug'] => $content,
        ];

        return $this->render($template, [], $globals);
    }
public function preview ( Request $ request , $ contenttypeslug ) { if ( ! $ request -> isMethod ( 'POST' ) ) { throw new MethodNotAllowedHttpException ( [ 'POST' ] , 'This route only accepts POST requests.' ) ; } $ contenttype = $ this -> getContentType ( $ contenttypeslug ) ; $ formValues = $ request -> request -> all ( ) ; $ storage = $ this -> storage ( ) ; if ( $ storage instanceof EntityManager ) { /** @var EntityManager $storage */ /** @var Content $content */ $ content = $ storage -> create ( $ contenttypeslug , $ formValues ) ; /** @var Collection\Relations $related */ $ related = $ storage -> createCollection ( Relations :: class ) ; $ related -> setFromPost ( $ formValues , $ content ) ; $ content -> setRelation ( $ related ) ; /** @var Collection\Taxonomy $taxonomies */ $ taxonomies = $ storage -> createCollection ( Taxonomy :: class ) ; $ taxonomies -> setFromPost ( $ formValues , $ content ) ; $ content -> setTaxonomy ( $ taxonomies ) ; } else { $ content = $ storage -> getContentObject ( $ contenttypeslug , [ ] , false ) ; $ content -> setFromPost ( $ formValues , $ contenttype ) ; } $ this -> fixBlockFieldsForPreview ( $ content ) ; $ this -> fixHTMLFieldsForPreview ( $ content ) ; $ liveEditor = $ request -> get ( '_live-editor-preview' ) ; if ( ! empty ( $ liveEditor ) ) { $ jsFile = ( new JavaScript ( 'js/ckeditor/ckeditor.js' , 'bolt' ) ) -> setPriority ( 1 ) -> setLate ( false ) ; $ cssFile = ( new Stylesheet ( 'css/liveeditor.css' , 'bolt' ) ) -> setPriority ( 5 ) -> setLate ( false ) ; $ snippet = ( new Snippet ( ) ) -> setCallback ( '<script>window.boltIsEditing = true;</script>' ) -> setLocation ( Target :: BEFORE_HEAD_JS ) ; $ this -> app [ 'asset.queue.snippet' ] -> add ( $ snippet ) ; $ this -> app [ 'asset.queue.file' ] -> add ( $ jsFile ) ; $ this -> app [ 'asset.queue.file' ] -> add ( $ cssFile ) ; } // Then, select which template to use, based on our 'cascading templates rules' $ template = $ this -> templateChooser ( ) -> record ( $ content ) ; // Make sure we can also access it as {{ page.title }} for pages, etc. We set these in the global scope, // So that they're also available in menu's and templates rendered by extensions. $ globals = [ 'record' => $ content , $ contenttype [ 'singular_slug' ] => $ content , ] ; return $ this -> render ( $ template , [ ] , $ globals ) ; }
The controller for previewing a content from posted data.

@param Request $request         The Symfony Request
@param string  $contenttypeslug The content type slug

@throws \Exception

@return TemplateResponse
The controller for previewing a content from posted data .