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

[BUGFIX] Ensure compatibility between v10 and v11 #231

Merged
merged 1 commit into from
Nov 18, 2021
Merged
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
189 changes: 36 additions & 153 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,18 @@

namespace T3G\AgencyPack\Blog\Controller;

use Psr\Http\Message\ResponseInterface;
use T3G\AgencyPack\Blog\Domain\Model\Comment;
use T3G\AgencyPack\Blog\Domain\Repository\CommentRepository;
use T3G\AgencyPack\Blog\Domain\Repository\PostRepository;
use T3G\AgencyPack\Blog\Service\CacheService;
use T3G\AgencyPack\Blog\Service\SetupService;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Backend\View\BackendTemplateView;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;

class BackendController extends ActionController
{
/**
* @var ModuleTemplate
*/
protected $moduleTemplate;

/**
* @var IconFactory
*/
protected $iconFactory;

/**
* @var ButtonBar
*/
protected $buttonBar;

/**
* @var SetupService
*/
Expand All @@ -61,6 +42,11 @@ class BackendController extends ActionController
*/
protected $blogCacheService;

/**
* @var string
*/
protected $defaultViewObjectName = BackendTemplateView::class;

/**
* @param SetupService $setupService
*/
Expand Down Expand Up @@ -93,96 +79,50 @@ public function injectBlogCacheService(CacheService $cacheService): void
$this->blogCacheService = $cacheService;
}

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

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

public function initializeSetupWizardAction(): void
/**
* @param ViewInterface $view
*/
protected function initializeView(ViewInterface $view)
{
$this->initializeDataTables();
$this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Blog/SetupWizard');
}
if ($view->getModuleTemplate() !== null) {
$pageRenderer = $view->getModuleTemplate()->getPageRenderer();

public function initializePostsAction(): void
{
$this->initializeDataTables();
}
$pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
$pageRenderer->loadRequireJsModule('TYPO3/CMS/Blog/Datatables');
$pageRenderer->loadRequireJsModule('TYPO3/CMS/Blog/SetupWizard');
$pageRenderer->loadRequireJsModule('TYPO3/CMS/Blog/MassUpdate');

public function initializeCommentsAction(): void
{
$this->initializeDataTables();
$this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Blog/MassUpdate');
}
$pageRenderer->addCssFile('EXT:blog/Resources/Public/Css/backend.min.css', 'stylesheet', 'all', '', false);
$pageRenderer->addCssFile('EXT:blog/Resources/Public/Css/Datatables.min.css', 'stylesheet', 'all', '', false);

protected function initializeDataTables(): void
{
$pageRenderer = $this->moduleTemplate->getPageRenderer();
$pageRenderer->loadRequireJsModule('TYPO3/CMS/Blog/Datatables');
$pageRenderer->addCssFile('EXT:blog/Resources/Public/Css/Datatables.min.css', 'stylesheet', 'all', '', false);
$view->assign('action', $this->actionMethodName);
}
}

/**
* Render the start page.
*
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidExtensionNameException
*
* @return string
*
* @throws \BadFunctionCallException
*/
public function setupWizardAction(): ResponseInterface
public function setupWizardAction()
{
return $this->htmlResponse($this->render('Backend/SetupWizard.html', [
'blogSetups' => $this->setupService->determineBlogSetups(),
]));
$this->view->assignMultiple([
'blogSetups' => $this->setupService->determineBlogSetups()
]);
}

/**
* @param int $blogSetup
* @return string
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidExtensionNameException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function postsAction(int $blogSetup = null): ResponseInterface
public function postsAction(int $blogSetup = null)
{
$query = $this->postRepository->createQuery();
$querySettings = $query->getQuerySettings();
$querySettings->setIgnoreEnableFields(true);
$this->postRepository->setDefaultQuerySettings($querySettings);

$html = $this->render('Backend/Posts.html', [
$this->view->assignMultiple([
'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;
}

/**
* @param string $filter
* @param int $blogSetup
*
* @return string
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidExtensionNameException
* @throws \InvalidArgumentException
*/
public function commentsAction(string $filter = null, int $blogSetup = null): ResponseInterface
public function commentsAction(string $filter = null, int $blogSetup = null)
{
$html = $this->render('Backend/Comments.html', [
$this->view->assignMultiple([
'activeFilter' => $filter,
'activeBlogSetup' => $blogSetup,
'commentCounts' => [
Expand All @@ -195,26 +135,15 @@ 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;
}

/**
* @param string $status
* @param string $filter
* @param int $blogSetup
* @param array $comments
* @param int $comment
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
* @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
): void {
if ($comment !== null) {
$comments['__identity'][] = $comment;
}
Expand Down Expand Up @@ -244,9 +173,6 @@ public function updateCommentStatusAction(string $status, string $filter = null,

/**
* @param array $data
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
* @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
*/
public function createBlogAction(array $data = null): void
{
Expand All @@ -257,47 +183,4 @@ public function createBlogAction(array $data = null): void
}
$this->redirect('setupWizard');
}

/**
* returns a new standalone view, shorthand function.
*
* @param string $templateNameAndPath
*
* @return StandaloneView
*
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidExtensionNameException
* @throws \InvalidArgumentException
*/
protected function getFluidTemplateObject(string $templateNameAndPath): StandaloneView
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:blog/Resources/Private/Layouts')]);
$view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:blog/Resources/Private/Partials')]);
$view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:blog/Resources/Private/Templates')]);
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:blog/Resources/Private/Templates/' . $templateNameAndPath));
$view->setControllerContext($this->getControllerContext());
$view->getRequest()->setControllerExtensionName('Blog');

return $view;
}

/**
* @param string $templateNameAndPath
* @param array $values
*
* @return string
*
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidExtensionNameException
* @throws \InvalidArgumentException
*/
protected function render(string $templateNameAndPath, array $values): string
{
$view = $this->getFluidTemplateObject($templateNameAndPath);
$view->assign('_template', $templateNameAndPath);
$view->assign('action', $this->actionMethodName);
$view->assignMultiple($values);
$this->moduleTemplate->setContent($view->render());

return $this->moduleTemplate->renderContent();
}
}
14 changes: 3 additions & 11 deletions Classes/Controller/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace T3G\AgencyPack\Blog\Controller;

use Psr\Http\Message\ResponseInterface;
use T3G\AgencyPack\Blog\Domain\Model\Comment;
use T3G\AgencyPack\Blog\Domain\Model\Post;
use T3G\AgencyPack\Blog\Domain\Repository\PostRepository;
Expand Down Expand Up @@ -61,22 +60,16 @@ public function injectBlogCacheService(CacheService $cacheService): void

/**
* Show comment form.
*
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function formAction(): ResponseInterface
public function formAction()
{
$this->view->assign('post', $this->postRepository->findCurrentPost());
return $this->htmlResponse();
}

/**
* @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* Show comments
*/
public function commentsAction(): ResponseInterface
public function commentsAction()
{
$post = $this->postRepository->findCurrentPost();
if ($post instanceof Post) {
Expand All @@ -87,6 +80,5 @@ public function commentsAction(): ResponseInterface
$this->view->assign('comments', $comments);
$this->view->assign('post', $post);
}
return $this->htmlResponse();
}
}
Loading