Skip to content
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
37 changes: 24 additions & 13 deletions Classes/Widget/CommentsWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,50 @@
* of the License, or any later version.
*/

use B13\Annotate\Domain\Repository\CommentRepository;
use Doctrine\DBAL\ParameterType;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\View\ViewFactoryData;
use TYPO3\CMS\Core\View\ViewFactoryInterface;
use TYPO3\CMS\Dashboard\Widgets\RequestAwareWidgetInterface;
use TYPO3\CMS\Dashboard\Widgets\WidgetConfigurationInterface;
use TYPO3\CMS\Dashboard\Widgets\WidgetInterface;
use TYPO3\CMS\Fluid\View\StandaloneView;

class CommentsWidget implements WidgetInterface
class CommentsWidget implements WidgetInterface, RequestAwareWidgetInterface
{
private ServerRequestInterface $request;

public function __construct(
protected WidgetConfigurationInterface $configuration,
protected StandaloneView $view,
protected CommentRepository $commentRepository,
protected ConnectionPool $connectionPool
private readonly WidgetConfigurationInterface $configuration,
private readonly ViewFactoryInterface $viewFactory,
private readonly ConnectionPool $connectionPool
) {}

public function setRequest(ServerRequestInterface $request): void
{
$this->request = $request;
}

public function renderWidgetContent(): string
{
$this->view->setTemplatePathAndFilename('EXT:annotate/Resources/Private/Templates/Widget/Comments.html');
$this->view->assignMultiple([
$view = $this->viewFactory->create(new ViewFactoryData(
layoutRootPaths: ['EXT:dashboard/Resources/Private/Layouts/'],
templateRootPaths: ['EXT:annotate/Resources/Private/Templates'],
request: $this->request
));
$view->assignMultiple([
'pages' => $this->getPagesWithComments(),
'configuration' => $this->configuration,
]);
return $this->view->render();
return $view->render('Widget/Comments');
}

protected function getPagesWithComments(): array
{
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
return $queryBuilder
->select('pages.uid', 'pages.title')
->add('select', 'COUNT(sys_comment.uid) AS commentCount', true)
->selectLiteral('COUNT(sys_comment.uid) AS commentCount')
->addSelect('pages.uid', 'pages.title')
->from('pages')
->innerJoin(
'pages',
Expand Down
2 changes: 0 additions & 2 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ services:

dashboard.widget.annotate:
class: B13\AnnotateWidget\Widget\CommentsWidget
arguments:
$view: '@dashboard.views.widget'
tags:
- name: dashboard.widget
identifier: annotate
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
"type": "typo3-cms-extension",
"description": "Extension providing a TYPO3 Dashboard widget for b13/annotate",
"require": {
"php": "^8",
"typo3/cms-core": "^11.5 || ^12.4",
"typo3/cms-dashboard": "^11.5 || ^12.4",
"typo3/cms-core": "^13.4 || ^14.1 || ^14.2.x-dev",
"typo3/cms-dashboard": "^13.4 || ^14.1 || ^14.2.x-dev",
"b13/annotate": "*"
},
"extra": {
Expand Down