Example #1
0
 /**
  * Renders the tag.
  *
  * @param \Netgen\TagsBundle\API\Repository\Values\Tags\Tag $tag
  * @param \Symfony\Component\HttpFoundation\Request $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function renderTag(Tag $tag, Request $request)
 {
     $configResolver = $this->getConfigResolver();
     if ($this->adapter instanceof TagAdapterInterface) {
         $this->adapter->setTag($tag);
     }
     $pager = new Pagerfanta($this->adapter);
     $pager->setMaxPerPage($configResolver->getParameter('tag_view.related_content_list.limit', 'eztags'));
     $pager->setCurrentPage($request->get('page', 1));
     $response = new Response();
     $response->headers->set('X-Tag-Id', $tag->id);
     if ($configResolver->getParameter('tag_view.cache', 'eztags') === true) {
         $response->setPublic();
         if ($configResolver->getParameter('tag_view.ttl_cache', 'eztags') === true) {
             $response->setSharedMaxAge($configResolver->getParameter('tag_view.default_ttl', 'eztags'));
         }
         // Make the response vary against X-User-Hash header ensures that an HTTP
         // reverse proxy caches the different possible variations of the
         // response as it can depend on user role for instance.
         if ($request->headers->has('X-User-Hash')) {
             $response->setVary('X-User-Hash');
         }
         $response->setLastModified($tag->modificationDate);
     }
     return $this->render($configResolver->getParameter('tag_view.template', 'eztags'), array('tag' => $tag, 'pager' => $pager), $response);
 }
 /**
  * Injects the pager with related content into the view.
  *
  * @param \eZ\Publish\Core\MVC\Symfony\View\Event\FilterViewParametersEvent $event
  */
 public function injectPager(FilterViewParametersEvent $event)
 {
     $view = $event->getView();
     if (!$view instanceof TagView) {
         return;
     }
     if ($this->adapter instanceof TagAdapterInterface) {
         $this->adapter->setTag($view->getTag());
     }
     $pager = new Pagerfanta($this->adapter);
     $pager->setNormalizeOutOfRangePages(true);
     $builderParameters = $event->getBuilderParameters();
     $pager->setMaxPerPage($this->pagerLimit > 0 ? $this->pagerLimit : 10);
     $pager->setCurrentPage($builderParameters['page'] > 0 ? $builderParameters['page'] : 1);
     $event->getParameterBag()->set('related_content', $pager);
 }