Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] v12 Support #4

Draft
wants to merge 13 commits into
base: master-upstream
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions Classes/AvatarProvider/GravatarProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

class GravatarProvider implements AvatarProviderInterface, SingletonInterface
{
Expand Down Expand Up @@ -63,13 +62,15 @@ final public function __construct()

public function getAvatarUrl(Author $author): string
{
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
$settings = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, 'blog');
$settings = [];
$frontendController = self::getTypoScriptFrontendController();
if ($frontendController instanceof TypoScriptFrontendController) {
$settings = $frontendController->tmpl->setup['plugin.']['tx_blog.']['settings.'] ?? [];
}

$size = empty($size = (string)($settings['authors']['avatar']['provider']['size'] ?? '')) ? null : (int)$size;
$rating = empty($rating = (string)($settings['authors']['avatar']['provider']['rating'] ?? '')) ? null : $rating;
$default = empty($default = (string)($settings['authors']['avatar']['provider']['default'] ?? '')) ? null : $default;
$size = empty($size = (string)($settings['authors.']['avatar.']['provider.']['size'] ?? '')) ? null : (int)$size;
$rating = empty($rating = (string)($settings['authors.']['avatar.']['provider.']['rating'] ?? '')) ? null : $rating;
$default = empty($default = (string)($settings['authors.']['avatar.']['provider.']['default'] ?? '')) ? null : $default;

$gravatarUri = $this->gravatarUriBuilder->getUri(
$author->getEmail(),
Expand Down Expand Up @@ -114,4 +115,9 @@ private function deriveFileTypeFromContentType(string $contentType): string
{
return substr($contentType, (int)strrpos($contentType, '/') + 1);
}

protected function getTypoScriptFrontendController(): ?TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
}
}
21 changes: 13 additions & 8 deletions Classes/AvatarProvider/ImageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
use T3G\AgencyPack\Blog\Domain\Model\Author;
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Service\ImageService;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

class ImageProvider implements AvatarProviderInterface
{
Expand All @@ -26,13 +25,14 @@ public function getAvatarUrl(Author $author): string
$image = $author->getImage();
if ($image instanceof FileReference) {
$defaultSize = 32;
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);

$configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
$settings = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, 'blog');
$size = ($settings['authors']['avatar']['provider']['size'] ?? $defaultSize) ?: $defaultSize;
$settings = [];
$frontendController = self::getTypoScriptFrontendController();
if ($frontendController instanceof TypoScriptFrontendController) {
$settings = $frontendController->tmpl->setup['plugin.']['tx_blog.']['settings.'] ?? [];
}
$size = ($settings['authors.']['avatar.']['provider.']['size'] ?? $defaultSize) ?: $defaultSize;

$imageService = $objectManager->get(ImageService::class);
$imageService = GeneralUtility::makeInstance(ImageService::class);
$image = $imageService->getImage('', $image, false);

if ($image->hasProperty('crop') && $image->getProperty('crop')) {
Expand All @@ -53,4 +53,9 @@ public function getAvatarUrl(Author $author): string
}
return '';
}

protected function getTypoScriptFrontendController(): ?TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
}
}
64 changes: 64 additions & 0 deletions Classes/Backend/View/BlogPostHeaderContentRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?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\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 PostRepository $postRepository;

public function __construct(PostRepository $postRepository)
{
$this->postRepository = $postRepository;
}

public function render(ServerRequestInterface $request): string
{
$pageUid = (int)($request->getParsedBody()['id'] ?? $request->getQueryParams()['id'] ?? 0);
$pageInfo = BackendUtility::readPageAccess($pageUid, $GLOBALS['BE_USER']->getPagePermsClause(Permission::PAGE_SHOW));

// Early exit for non-blog pages
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;
}
}
1 change: 0 additions & 1 deletion Classes/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class Constants
'blog_comments' => -1600000008,
'blog_header' => -1600000009,
'blog_footer' => -1600000010,
'blog_metadata' => -1600000011,
'blog_authors' => -1600000012,
'blog_relatedposts' => -1600000013,
'blog_recentpostswidget' => -1600000014,
Expand Down
74 changes: 48 additions & 26 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
use T3G\AgencyPack\Blog\Service\SetupService;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Core\Http\RedirectResponse;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Fluid\View\StandaloneView;
Expand Down Expand Up @@ -60,6 +62,18 @@ class BackendController extends ActionController
* @var CacheService
*/
protected $blogCacheService;
private \TYPO3\CMS\Core\Page\PageRenderer $pageRenderer;
protected ModuleTemplateFactory $moduleTemplateFactory;

public function __construct(
\TYPO3\CMS\Core\Imaging\IconFactory $iconFactory,
\TYPO3\CMS\Core\Page\PageRenderer $pageRenderer,
ModuleTemplateFactory $moduleTemplateFactory
) {
$this->iconFactory = $iconFactory;
$this->pageRenderer = $pageRenderer;
$this->moduleTemplateFactory = $moduleTemplateFactory;
}

/**
* @param SetupService $setupService
Expand Down Expand Up @@ -95,19 +109,18 @@ public function injectBlogCacheService(CacheService $cacheService): void

public function initializeAction(): void
{
$this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
$this->iconFactory = $this->moduleTemplate->getIconFactory();
$this->moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$this->buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();

$pageRenderer = $this->moduleTemplate->getPageRenderer();
$pageRenderer = $this->pageRenderer;
$pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
$pageRenderer->addCssFile('EXT:blog/Resources/Public/Css/backend.min.css', 'stylesheet', 'all', '', false);
}

public function initializeSetupWizardAction(): void
{
$this->initializeDataTables();
$this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Blog/SetupWizard');
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Blog/SetupWizard');
}

public function initializePostsAction(): void
Expand All @@ -118,12 +131,12 @@ public function initializePostsAction(): void
public function initializeCommentsAction(): void
{
$this->initializeDataTables();
$this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Blog/MassUpdate');
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Blog/MassUpdate');
}

protected function initializeDataTables(): void
{
$pageRenderer = $this->moduleTemplate->getPageRenderer();
$pageRenderer = $this->pageRenderer;
$pageRenderer->loadRequireJsModule('TYPO3/CMS/Blog/Datatables');
$pageRenderer->addCssFile('EXT:blog/Resources/Public/Css/Datatables.min.css', 'stylesheet', 'all', '', false);
}
Expand All @@ -140,9 +153,9 @@ protected function initializeDataTables(): void
*/
public function setupWizardAction(): ResponseInterface
{
return $this->htmlResponse($this->render('Backend/SetupWizard.html', [
return $this->renderResponse('Backend/SetupWizard.html', [
'blogSetups' => $this->setupService->determineBlogSetups(),
]));
]);
}

/**
Expand All @@ -158,16 +171,11 @@ public function postsAction(int $blogSetup = null): ResponseInterface
$querySettings = $query->getQuerySettings();
$querySettings->setIgnoreEnableFields(true);
$this->postRepository->setDefaultQuerySettings($querySettings);

$html = $this->render('Backend/Posts.html', [
return $this->renderResponse('Backend/Posts.html', [
'blogSetups' => $this->setupService->determineBlogSetups(),
'activeBlogSetup' => $blogSetup,
'posts' => $this->postRepository->findAllByPid($blogSetup),
]);
$response = $this->responseFactory->createResponse()
->withHeader('Content-Type', 'text/html; charset=utf-8');
$response->getBody()->write($html ?? $this->view->render());
return $response;
}

/**
Expand All @@ -182,7 +190,7 @@ public function postsAction(int $blogSetup = null): ResponseInterface
*/
public function commentsAction(string $filter = null, int $blogSetup = null): ResponseInterface
{
$html = $this->render('Backend/Comments.html', [
return $this->renderResponse('Backend/Comments.html', [
'activeFilter' => $filter,
'activeBlogSetup' => $blogSetup,
'commentCounts' => [
Expand All @@ -195,10 +203,6 @@ public function commentsAction(string $filter = null, int $blogSetup = null): Re
'blogSetups' => $this->setupService->determineBlogSetups(),
'comments' => $this->commentRepository->findAllByFilter($filter, $blogSetup),
]);
$response = $this->responseFactory->createResponse()
->withHeader('Content-Type', 'text/html; charset=utf-8');
$response->getBody()->write($html ?? $this->view->render());
return $response;
}

/**
Expand All @@ -213,7 +217,7 @@ public function commentsAction(string $filter = null, int $blogSetup = null): Re
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
*/
public function updateCommentStatusAction(string $status, string $filter = null, int $blogSetup = null, array $comments = [], int $comment = null): void
public function updateCommentStatusAction(string $status, string $filter = null, int $blogSetup = null, array $comments = [], int $comment = null): ResponseInterface
{
if ($comment !== null) {
$comments['__identity'][] = $comment;
Expand All @@ -239,7 +243,8 @@ public function updateCommentStatusAction(string $status, string $filter = null,
$this->blogCacheService->flushCacheByTag('tx_blog_comment_' . $comment->getUid());
}
}
$this->redirect('comments', null, null, ['filter' => $filter, 'blogSetup' => $blogSetup]);
$uri = $this->uriBuilder->reset()->uriFor('comments', ['filter' => $filter, 'blogSetup' => $blogSetup]);
return new RedirectResponse($uri);
}

/**
Expand All @@ -248,14 +253,15 @@ public function updateCommentStatusAction(string $status, string $filter = null,
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
* @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
*/
public function createBlogAction(array $data = null): void
public function createBlogAction(array $data = null): ResponseInterface
{
if ($this->setupService->createBlogSetup($data)) {
$this->addFlashMessage('Your blog setup has been created.', 'Congratulation');
} else {
$this->addFlashMessage('Sorry, your blog setup could not be created.', 'An error occurred', FlashMessage::ERROR);
$this->addFlashMessage('Sorry, your blog setup could not be created.', 'An error occurred', \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR);
}
$this->redirect('setupWizard');
$uri = $this->uriBuilder->reset()->uriFor('setupWizard');
return new RedirectResponse($uri);
}

/**
Expand All @@ -277,7 +283,6 @@ protected function getFluidTemplateObject(string $templateNameAndPath): Standalo
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:blog/Resources/Private/Templates/' . $templateNameAndPath));
$view->setControllerContext($this->getControllerContext());
$view->getRequest()->setControllerExtensionName('Blog');

return $view;
}

Expand All @@ -295,9 +300,26 @@ protected function render(string $templateNameAndPath, array $values): string
$view = $this->getFluidTemplateObject($templateNameAndPath);
$view->assign('_template', $templateNameAndPath);
$view->assign('action', $this->actionMethodName);
$view->assign('layout', 'Backend');
$view->assignMultiple($values);
$this->moduleTemplate->setContent($view->render());

return $this->moduleTemplate->renderContent();
}

protected function renderResponse(string $templateName, array $values): ResponseInterface
{
if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() < 12) {
$html = $this->render($templateName, $values);
$response = $this->responseFactory->createResponse()
->withHeader('Content-Type', 'text/html; charset=utf-8');
$response->getBody()->write($html ?? $this->view->render());
return $response;
}
$this->moduleTemplate->assignMultiple(array_merge(
['_template' => $templateName, 'action' => $this->actionMethodName, 'layout' => 'Module'],
$values
));
return $this->moduleTemplate->renderResponse($templateName);
}
}
Loading