Skip to content

Commit

Permalink
Merge branch 'master' into release-2015.09
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertrand Dunogier committed Oct 22, 2015
2 parents 9851c9b + 99dc9ac commit d9f5bcb
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 343 deletions.
97 changes: 32 additions & 65 deletions Controller/DemoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

use eZ\Bundle\EzPublishCoreBundle\Controller;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\Core\MVC\Symfony\View\ContentView;
use eZ\Publish\Core\MVC\Symfony\View\View;
use eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchAdapter;
use Pagerfanta\Pagerfanta;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use eZ\Publish\API\Repository\Values\Content\Query;
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;

Expand All @@ -41,23 +42,20 @@ public function userLinksAction()
/**
* Renders article with extra parameters that controls page elements visibility such as image and summary.
*
* @param $locationId
* @param $viewType
* @param bool $layout
* @param array $params
* @param \eZ\Publish\Core\MVC\Symfony\View\View $view
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function showArticleAction($locationId, $viewType, $layout = false, array $params = array())
public function showArticleAction(View $view)
{
return $this->get('ez_content')->viewLocation(
$locationId,
$viewType,
$layout,
array(
$view->addParameters(
[
'showSummary' => $this->container->getParameter('ezdemo.article.full_view.show_summary'),
'showImage' => $this->container->getParameter('ezdemo.article.full_view.show_image'),
) + $params
]
);

return $view;
}

/**
Expand All @@ -66,39 +64,24 @@ public function showArticleAction($locationId, $viewType, $layout = false, array
* the view. Since it is not calling the ViewControler we don't need to match a specific
* method signature.
*
* @param \eZ\Publish\API\Repository\Values\Content\Location $location containing blog posts
* @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function listBlogPostsAction(Location $location, Request $request)
public function listBlogPostsAction(ContentView $view, Request $request)
{
$response = new Response();

// Setting default cache configuration (you can override it in you siteaccess config)
$response->setSharedMaxAge($this->getConfigResolver()->getParameter('content.default_ttl'));

// Make the response location cache aware for the reverse proxy
$response->headers->set('X-Location-Id', $location->id);
$response->setVary('X-User-Hash');

$viewParameters = $request->attributes->get('viewParameters');

// Getting location and content from ezpublish dedicated services
$repository = $this->getRepository();
if ($location->invisible) {
throw new NotFoundHttpException("Location #$location->id cannot be displayed as it is flagged as invisible.");
}

$content = $repository
->getContentService()
->loadContentByContentInfo($location->getContentInfo());

// Getting language for the current siteaccess
// This could be changed to use dynamic parameters injection
$languages = $this->getConfigResolver()->getParameter('languages');

// Using the criteria helper (a demobundle custom service) to generate our query's criteria.
// This is a good practice in order to have less code in your controller.
$criteria = $this->get('ezdemo.criteria_helper')->generateListBlogPostCriterion(
$location, $viewParameters, $languages
$view->getLocation(),
$viewParameters,
$languages
);

// Generating query
Expand All @@ -115,15 +98,12 @@ public function listBlogPostsAction(Location $location, Request $request)
$pager->setMaxPerPage($this->container->getParameter('ezdemo.blog.blog_post_list.limit'));
$pager->setCurrentPage($request->get('page', 1));

return $this->render(
'eZDemoBundle:full:blog.html.twig',
array(
'location' => $location,
'content' => $content,
'pagerBlog' => $pager,
),
$response
);
$view->addParameters(['pagerBlog' => $pager]);

// The template identifier can be set from the controller action
$view->setTemplateIdentifier('eZDemoBundle:full:blog.html.twig');

return $view;
}

/**
Expand All @@ -133,29 +113,16 @@ public function listBlogPostsAction(Location $location, Request $request)
* Viewcontroller's viewLocation method. To be able to do that, we need to implement it's
* full signature.
*
* @param \eZ\Publish\API\Repository\Values\Content\Location $location of the blog post
* @param $viewType
* @param bool $layout
* @param array $params
* @return \Symfony\Component\HttpFoundation\Response
* @param ContentView $view
*
* @return View
*/
public function showBlogPostAction(Location $location, $viewType, $layout = false, array $params = array())
public function showBlogPostAction(ContentView $view)
{
// We need the author, whatever the view type is.
$repository = $this->getRepository();
$author = $repository->getUserService()->loadUser($location->getContentInfo()->ownerId);

// TODO once the keyword service is available, load the number of keyword for each keyword

// Delegate view rendering to the original ViewController
// (makes it possible to continue using defined template rules)
// We just add "author" to the list of variables exposed to the final template
return $this->get('ez_content')->viewLocation(
$location->id,
$viewType,
$layout,
array('author' => $author) + $params
);
$author = $this->getRepository()->getUserService()->loadUser($view->getContent()->contentInfo->ownerId);
$view->addParameters(['author' => $author]);

return $view;
}

/**
Expand Down
28 changes: 12 additions & 16 deletions Controller/FeedbackFormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,24 @@
namespace EzSystems\DemoBundle\Controller;

use eZ\Bundle\EzPublishCoreBundle\Controller;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\Core\MVC\Symfony\View\ContentView;
use EzSystems\DemoBundle\Entity\Feedback;
use EzSystems\DemoBundle\Helper\EmailHelper;
use Symfony\Component\HttpFoundation\Request;

class FeedbackFormController extends Controller
{
/**
* Displays and manages the feedback form.
* Displays the feedback form, and processes posted data.
* The signature of this method follows the one from the default view controller, and adds the Request, since
* we use to handle form data.
*
* The signature of this method follows the one from the default view controller.
* @param \eZ\Publish\API\Repository\Values\Content\Location $location
* @param $viewType
* @param bool $layout
* @param array $params
* @param \Symfony\Component\HttpFoundation\Request $request
* @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
*
* @return mixed
* @return View
*/
public function showFeedbackFormAction(Request $request, Location $location, $viewType, $layout = false, array $params = array())
public function showFeedbackFormAction(Request $request, ContentView $view)
{
// Creating a form using Symfony's form component
$feedback = new Feedback();
Expand All @@ -51,15 +50,12 @@ public function showFeedbackFormAction(Request $request, Location $location, $vi
$this->get('translator')->trans('Thank you for your message, we will get back to you as soon as possible.')
);

return $this->redirect($this->generateUrl($location));
return $this->redirect($this->generateUrl($view->getLocation()));
}
}

return $this->get('ez_content')->viewLocation(
$location->id,
$viewType,
$layout,
array('form' => $form->createView()) + $params
);
$view->addParameters(['form' => $form->createView()]);

return $view;
}
}
62 changes: 22 additions & 40 deletions Controller/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,27 @@
use eZ\Publish\API\Repository\Values\Content\LocationQuery;
use eZ\Publish\API\Repository\Values\Content\Query;
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\Core\MVC\Symfony\View\ContentView;
use eZ\Publish\Core\Pagination\Pagerfanta\ContentSearchAdapter;
use eZ\Bundle\EzPublishCoreBundle\Controller;
use Pagerfanta\Pagerfanta;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Request;

class FolderController extends Controller
{
/**
* Displays the sub folder if it exists.
*
* @param \eZ\Publish\API\Repository\Values\Content\Location $location of a folder
* @throws NotFoundHttpException $location is flagged as invisible
* @return \Symfony\Component\HttpFoundation\Response
* @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
*
* @return \Symfony\Component\HttpFoundation\Response $location is flagged as invisible
*/
public function showFolderListAsideViewAction(Location $location)
public function showFolderListAsideViewAction(ContentView $view)
{
if ($location->invisible) {
throw new NotFoundHttpException("Location #$location->id cannot be displayed as it is flagged as invisible.");
}

$languages = $this->getConfigResolver()->getParameter('languages');

$includedContentTypeIdentifiers = $this->container->getParameter('ezdemo.folder.folder_tree.included_content_types');

$subContentCriteria = $this->get('ezdemo.criteria_helper')->generateSubContentCriterion(
$location, $includedContentTypeIdentifiers, $languages
$view->getLocation(),
$this->container->getParameter('ezdemo.folder.folder_tree.included_content_types'),
$this->getConfigResolver()->getParameter('languages')
);

$subContentQuery = new LocationQuery();
Expand All @@ -56,37 +49,29 @@ public function showFolderListAsideViewAction(Location $location)
$treeChildItems[] = $hit->valueObject;
}

return $this->get('ez_content')->viewLocation(
$location->id,
'aside_sub',
true,
['treeChildItems' => $treeChildItems]
);
$view->addParameters(['treeChildItems' => $treeChildItems]);

return $view;
}

/**
* Displays the list of article.
*
* @param \eZ\Publish\API\Repository\Values\Content\Location $location of a folder
* @param \Symfony\Component\HttpFoundation\Request $request request object
* @throws NotFoundHttpException $location is flagged as invisible
* @return \Symfony\Component\HttpFoundation\Response
* @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
*
* @return \Symfony\Component\HttpFoundation\Response $location is flagged as invisible
*/
public function showFolderListAction(Request $request, Location $location)
public function showFolderListAction(Request $request, ContentView $view)
{
if ($location->invisible) {
throw new NotFoundHttpException("Location #$location->id cannot be displayed as it is flagged as invisible.");
}

// Getting language for the current siteaccess
$languages = $this->getConfigResolver()->getParameter('languages');

$excludedContentTypes = $this->container->getParameter('ezdemo.folder.folder_view.excluded_content_types');

// Using the criteria helper (a demobundle custom service) to generate our query's criteria.
// This is a good practice in order to have less code in your controller.
$criteria = $this->get('ezdemo.criteria_helper')->generateListFolderCriterion(
$location, $excludedContentTypes, $languages
$view->getLocation(),
$this->container->getParameter('ezdemo.folder.folder_view.excluded_content_types'),
$languages
);

// Generating query
Expand All @@ -108,7 +93,7 @@ public function showFolderListAction(Request $request, Location $location)

// Get sub folder structure
$subContentCriteria = $this->get('ezdemo.criteria_helper')->generateSubContentCriterion(
$location, $includedContentTypeIdentifiers, $languages
$view->getLocation(), $includedContentTypeIdentifiers, $languages
);

$subContentQuery = new LocationQuery();
Expand All @@ -125,11 +110,8 @@ public function showFolderListAction(Request $request, Location $location)
$treeItems[] = $hit->valueObject;
}

return $this->get('ez_content')->viewLocation(
$location->id,
'full',
true,
['pagerFolder' => $pager, 'treeItems' => $treeItems]
);
$view->addParameters(['pagerFolder' => $pager, 'treeItems' => $treeItems]);

return $view;
}
}
16 changes: 12 additions & 4 deletions PremiumContent/PremiumLocationViewProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

use eZ\Publish\API\Repository\Repository;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\Core\MVC\Symfony\View\ContentValueView;
use eZ\Publish\Core\MVC\Symfony\View\ContentView;
use eZ\Publish\Core\MVC\Symfony\View\Provider\Location as LocationViewProvider;
use eZ\Publish\Core\MVC\Symfony\View\View;
use eZ\Publish\Core\MVC\Symfony\View\ViewProvider;

/**
* Returns the premium_content view if it applies to a location and if the user isn't a Premium subscriber.
*/
class PremiumLocationViewProvider implements LocationViewProvider
class PremiumLocationViewProvider implements ViewProvider
{
/**
* ID of the section used to mark content as Premium.
Expand All @@ -38,13 +40,19 @@ public function __construct(Repository $repository, PremiumSubscriptionChecker $
$this->subscriptionChecker = $subscriptionChecker;
}

public function getView(Location $location, $viewType)
public function getView(View $view)
{
$viewType = $view->getViewType();

if ($viewType !== 'full') {
return null;
}

if ($location->getContentInfo()->sectionId !== $this->premiumSectionId) {
if (!$view instanceof ContentValueView) {
return null;
}

if ($view->getContent()->contentInfo->sectionId !== $this->premiumSectionId) {
return null;
}

Expand Down
Loading

0 comments on commit d9f5bcb

Please sign in to comment.