-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Move backend post header to dedicated renderer
- Loading branch information
1 parent
4de4bcd
commit 1fbde27
Showing
4 changed files
with
88 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
/* | ||
* This file is part of the package t3g/blog. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace T3G\AgencyPack\Blog\Backend\View; | ||
|
||
use Psr\Http\Message\ServerRequestInterface; | ||
use T3G\AgencyPack\Blog\Constants; | ||
use T3G\AgencyPack\Blog\Domain\Repository\PostRepository; | ||
use TYPO3\CMS\Backend\Utility\BackendUtility; | ||
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; | ||
use TYPO3\CMS\Core\Page\PageRenderer; | ||
use TYPO3\CMS\Core\SingletonInterface; | ||
use TYPO3\CMS\Core\Type\Bitmask\Permission; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Fluid\View\StandaloneView; | ||
|
||
class BlogPostHeaderContentRenderer implements SingletonInterface | ||
{ | ||
protected ExtensionConfiguration $extensionConfiguration; | ||
protected PostRepository $postRepository; | ||
|
||
public function __construct( | ||
ExtensionConfiguration $extensionConfiguration, | ||
PostRepository $postRepository | ||
) { | ||
$this->extensionConfiguration = $extensionConfiguration; | ||
$this->postRepository = $postRepository; | ||
} | ||
|
||
public function render(ServerRequestInterface $request): string | ||
{ | ||
$blogConfiguration = $this->extensionConfiguration->get('blog'); | ||
if ((bool)($blogConfiguration['disablePageLayoutHeader']) ?? true) { | ||
return ''; | ||
} | ||
|
||
$pageUid = (int)($request->getParsedBody()['id'] ?? $request->getQueryParams()['id'] ?? 0); | ||
$pageInfo = BackendUtility::readPageAccess($pageUid, $GLOBALS['BE_USER']->getPagePermsClause(Permission::PAGE_SHOW)); | ||
if (($pageInfo['doktype'] ?? 0) !== Constants::DOKTYPE_BLOG_POST) { | ||
return ''; | ||
} | ||
|
||
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); | ||
$pageRenderer->addCssFile('EXT:blog/Resources/Public/Css/pagelayout.min.css', 'stylesheet', 'all', '', false); | ||
|
||
$query = $this->postRepository->createQuery(); | ||
$querySettings = $query->getQuerySettings(); | ||
$querySettings->setIgnoreEnableFields(true); | ||
$this->postRepository->setDefaultQuerySettings($querySettings); | ||
$post = $this->postRepository->findByUidRespectQuerySettings($pageUid); | ||
|
||
$view = GeneralUtility::makeInstance(StandaloneView::class); | ||
$view->getRenderingContext()->getTemplatePaths()->fillDefaultsByPackageName('blog'); | ||
$view->setTemplate('PageLayout/Header'); | ||
$view->assignMultiple([ | ||
'pageUid' => $pageUid, | ||
'pageInfo' => $pageInfo, | ||
'post' => $post, | ||
]); | ||
|
||
$content = $view->render(); | ||
return $content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters