1010
1111use eZ \Bundle \EzPublishCoreBundle \Controller ;
1212use eZ \Publish \API \Repository \Values \Content \Location ;
13+ use eZ \Publish \Core \MVC \Symfony \View \ContentView ;
14+ use eZ \Publish \Core \MVC \Symfony \View \View ;
1315use eZ \Publish \Core \Pagination \Pagerfanta \ContentSearchAdapter ;
1416use Pagerfanta \Pagerfanta ;
1517use Symfony \Component \HttpFoundation \Request ;
1618use Symfony \Component \HttpFoundation \Response ;
17- use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
1819use eZ \Publish \API \Repository \Values \Content \Query ;
1920use eZ \Publish \API \Repository \Values \Content \Query \SortClause ;
2021
@@ -41,23 +42,20 @@ public function userLinksAction()
4142 /**
4243 * Renders article with extra parameters that controls page elements visibility such as image and summary.
4344 *
44- * @param $locationId
45- * @param $viewType
46- * @param bool $layout
47- * @param array $params
45+ * @param \eZ\Publish\Core\MVC\Symfony\View\View $view
46+ *
4847 * @return \Symfony\Component\HttpFoundation\Response
4948 */
50- public function showArticleAction ($ locationId , $ viewType , $ layout = false , array $ params = array () )
49+ public function showArticleAction (View $ view )
5150 {
52- return $ this ->get ('ez_content ' )->viewLocation (
53- $ locationId ,
54- $ viewType ,
55- $ layout ,
56- array (
51+ $ view ->addParameters (
52+ [
5753 'showSummary ' => $ this ->container ->getParameter ('ezdemo.article.full_view.show_summary ' ),
5854 'showImage ' => $ this ->container ->getParameter ('ezdemo.article.full_view.show_image ' ),
59- ) + $ params
55+ ]
6056 );
57+
58+ return $ view ;
6159 }
6260
6361 /**
@@ -66,39 +64,24 @@ public function showArticleAction($locationId, $viewType, $layout = false, array
6664 * the view. Since it is not calling the ViewControler we don't need to match a specific
6765 * method signature.
6866 *
69- * @param \eZ\Publish\API\Repository\Values\Content\Location $location containing blog posts
67+ * @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
68+ * @param \Symfony\Component\HttpFoundation\Request $request
69+ *
7070 * @return \Symfony\Component\HttpFoundation\Response
7171 */
72- public function listBlogPostsAction (Location $ location , Request $ request )
72+ public function listBlogPostsAction (ContentView $ view , Request $ request )
7373 {
74- $ response = new Response ();
75-
76- // Setting default cache configuration (you can override it in you siteaccess config)
77- $ response ->setSharedMaxAge ($ this ->getConfigResolver ()->getParameter ('content.default_ttl ' ));
78-
79- // Make the response location cache aware for the reverse proxy
80- $ response ->headers ->set ('X-Location-Id ' , $ location ->id );
81- $ response ->setVary ('X-User-Hash ' );
82-
8374 $ viewParameters = $ request ->attributes ->get ('viewParameters ' );
8475
85- // Getting location and content from ezpublish dedicated services
86- $ repository = $ this ->getRepository ();
87- if ($ location ->invisible ) {
88- throw new NotFoundHttpException ("Location # $ location ->id cannot be displayed as it is flagged as invisible. " );
89- }
90-
91- $ content = $ repository
92- ->getContentService ()
93- ->loadContentByContentInfo ($ location ->getContentInfo ());
94-
95- // Getting language for the current siteaccess
76+ // This could be changed to use dynamic parameters injection
9677 $ languages = $ this ->getConfigResolver ()->getParameter ('languages ' );
9778
9879 // Using the criteria helper (a demobundle custom service) to generate our query's criteria.
9980 // This is a good practice in order to have less code in your controller.
10081 $ criteria = $ this ->get ('ezdemo.criteria_helper ' )->generateListBlogPostCriterion (
101- $ location , $ viewParameters , $ languages
82+ $ view ->getLocation (),
83+ $ viewParameters ,
84+ $ languages
10285 );
10386
10487 // Generating query
@@ -115,15 +98,12 @@ public function listBlogPostsAction(Location $location, Request $request)
11598 $ pager ->setMaxPerPage ($ this ->container ->getParameter ('ezdemo.blog.blog_post_list.limit ' ));
11699 $ pager ->setCurrentPage ($ request ->get ('page ' , 1 ));
117100
118- return $ this ->render (
119- 'eZDemoBundle:full:blog.html.twig ' ,
120- array (
121- 'location ' => $ location ,
122- 'content ' => $ content ,
123- 'pagerBlog ' => $ pager ,
124- ),
125- $ response
126- );
101+ $ view ->addParameters (['pagerBlog ' => $ pager ]);
102+
103+ // The template identifier can be set from the controller action
104+ $ view ->setTemplateIdentifier ('eZDemoBundle:full:blog.html.twig ' );
105+
106+ return $ view ;
127107 }
128108
129109 /**
@@ -133,29 +113,16 @@ public function listBlogPostsAction(Location $location, Request $request)
133113 * Viewcontroller's viewLocation method. To be able to do that, we need to implement it's
134114 * full signature.
135115 *
136- * @param \eZ\Publish\API\Repository\Values\Content\Location $location of the blog post
137- * @param $viewType
138- * @param bool $layout
139- * @param array $params
140- * @return \Symfony\Component\HttpFoundation\Response
116+ * @param ContentView $view
117+ *
118+ * @return View
141119 */
142- public function showBlogPostAction (Location $ location , $ viewType , $ layout = false , array $ params = array () )
120+ public function showBlogPostAction (ContentView $ view )
143121 {
144- // We need the author, whatever the view type is.
145- $ repository = $ this ->getRepository ();
146- $ author = $ repository ->getUserService ()->loadUser ($ location ->getContentInfo ()->ownerId );
147-
148- // TODO once the keyword service is available, load the number of keyword for each keyword
149-
150- // Delegate view rendering to the original ViewController
151- // (makes it possible to continue using defined template rules)
152- // We just add "author" to the list of variables exposed to the final template
153- return $ this ->get ('ez_content ' )->viewLocation (
154- $ location ->id ,
155- $ viewType ,
156- $ layout ,
157- array ('author ' => $ author ) + $ params
158- );
122+ $ author = $ this ->getRepository ()->getUserService ()->loadUser ($ view ->getContent ()->contentInfo ->ownerId );
123+ $ view ->addParameters (['author ' => $ author ]);
124+
125+ return $ view ;
159126 }
160127
161128 /**
0 commit comments