<?php declare(strict_types=1);
namespace NetzpBlog6\Controller;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Symfony\Component\Routing\Annotation\Route;
use Shopware\Storefront\Framework\Cache\Annotation\HttpCache;
use NetzpBlog6\Storefront\Page\BlogPageLoader;
use Shopware\Core\Framework\Context;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Storefront\Controller\StorefrontController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use NetzpBlog6\Helper\BlogHelper;
/**
* @RouteScope(scopes={"storefront"})
*/
class BlogController extends StorefrontController
{
private $helper;
private $blogPageLoader;
private $config;
public function __construct(
BlogHelper $helper,
BlogPageLoader $blogPageLoader,
SystemConfigService $config)
{
$this->helper = $helper;
$this->blogPageLoader = $blogPageLoader;
$this->config = $config;
}
/**
* @Route("/blog.rss", name="frontend.blog.feed", methods={"GET"})
*/
public function getFeed(Request $request, SalesChannelContext $salesChannelContext, Context $context)
{
$posts = $this->helper->getPublicBlogPosts($salesChannelContext, $context, null, null, true);
$response = $this->renderStorefront('storefront/page/blog/feed.html.twig', [
'posts' => $posts
]);
$response->headers->set('Content-Type', 'text/xml');
return $response;
}
/**
* @HttpCache()
* @Route("/blog/{postId}", name="frontend.blog.post", methods={"GET"})
*/
public function getPost(Request $request, SalesChannelContext $salesChannelContext, Context $context, $postId)
{
$shariffIsActive = $this->helper->isPluginActive('NetzpShariff6', $context);
$config = $this->config->get('NetzpBlog6.config', $salesChannelContext->getSalesChannel()->getId());
$page = $this->blogPageLoader->load($request, $salesChannelContext, $postId);
$template = $page->isCmsPage() ? 'storefront/page/content/index.html.twig' : 'storefront/page/blog/post.html.twig';
return $this->renderStorefront($template, [
'page' => $page,
'post' => $page->getPost(),
'config' => $config,
'netzpShariffActive' => $shariffIsActive
]);
}
}