mirror of https://github.com/FriendsOfTYPO3/tea.git synced 2024-12-03 18:16:13 +01:00

[TASK] Use rating controller and index controller in new Plugin (#893)

This commit is contained in:
mdt 2024-05-07 16:23:04 +02:00 committed by marko deutscher
parent 5349412184
commit e5e997cfde
10 changed files with 162 additions and 15 deletions

View file

@ -2,17 +2,19 @@
namespace TTN\Tea\Controller;
use Psr\Http\Message\ResponseInterface;
use TTN\Tea\Domain\Model\Product\Tea;
use TTN\Tea\Domain\Repository\Product\TeaRepository;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Extbase\Persistence\Generic\QueryResult;
use TTN\Tea\Domain\Model\Tea;
use TTN\Tea\Domain\Repository\TeaRepository;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
class RatingController extends FrontEndEditorController
class RatingController extends ActionController
{
public function __construct(protected TeaRepository $teaRepository)
{
}
public function ratingAction(Tea $tea, int $stars)
{
$this->checkIfUserIsOwner($tea);
$tea->setStars($stars);
$this->teaRepository->update($tea);

View file

@ -30,10 +30,18 @@ call_user_func(
'EXT:tea/Resources/Public/Icons/Extension.svg'
);
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'Tea',
'TeaRating',
'LLL:EXT:tea/Resources/Private/Language/locallang.xlf:plugin.tea_rating',
'EXT:tea/Resources/Public/Icons/Extension.svg'
);
// This removes the default controls from the plugin.
$controlsToRemove = 'recursive,pages';
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist']['tea_teaindex'] = $controlsToRemove;
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist']['tea_teashow'] = $controlsToRemove;
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist']['tea_teafrontendeditor'] = $controlsToRemove;
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist']['tea_tearating'] = $controlsToRemove;
}
);

View file

@ -21,3 +21,27 @@ plugin.tx_tea {
singleViewPageUid = {$plugin.tx_tea.settings.singleViewPageUid}
}
}
plugin.tx_tea_tearating {
view {
templateRootPaths {
0 = EXT:tea/Resources/Private/Plugins/Rating/Templates/
}
partialRootPaths {
0 = EXT:tea/Resources/Private/Plugins/Rating/Partials/
}
layoutRootPaths {
0 = EXT:tea/Resources/Private/Plugins/Rating/Layouts/
}
}
persistence {
storagePid = {$plugin.tx_tea.persistence.storagePid}
}
settings {
singleViewPageUid = {$plugin.tx_tea_tearating.settings.singleViewPageUid}
}
}

View file

@ -11,6 +11,10 @@
<source>Tea single view</source>
<target>Tee-Einzelansicht</target>
</trans-unit>
<trans-unit id="plugin.tea_rating" resname="plugin.tea_rating">
<source>Tea Rating view</source>
<target>Tee-Bewertungsansicht</target>
</trans-unit>
<trans-unit id="plugin.tea_frontend_editor" resname="plugin.tea_frontend_editor" approved="yes">
<source>Tea front-end editor</source>
<target>Frontend-Editor für Tee</target>

View file

@ -9,6 +9,9 @@
<trans-unit id="plugin.tea_show" resname="plugin.tea_show">
<source>Tea single view</source>
</trans-unit>
<trans-unit id="plugin.tea_rating" resname="plugin.tea_rating">
<source>Tea Rating view</source>
</trans-unit>
<trans-unit id="plugin.tea_frontend_editor" resname="plugin.tea_frontend_editor">
<source>Tea front-end editor</source>
</trans-unit>
@ -66,6 +69,10 @@
<trans-unit id="plugin.frontEndEditor.new.heading" resname="plugin.frontEndEditor.new.heading">
<source>Create new tea</source>
</trans-unit>
<trans-unit id="plugin.tea.filter.rating" resname="plugin.tea.filter.rating">
<source>Filter by rating</source>
</trans-unit>
</body>
</file>
</xliff>

View file

@ -0,0 +1,41 @@
<!DOCTYPE html>
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default"/>
<f:section name="main">
<h2>
Rating Plugin: <f:translate key="plugin.tea.heading"/>
</h2>
<f:link.action action="filter" controller="Rating" arguments="{stars:1}">1</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:2}">2</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:3}">3</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:4}">4</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:5}">5</f:link.action>
<table class="table">
<thead>
<tr>
<th>
<f:translate key="plugin.tea.property.uid"/>
</th>
<th>
<f:translate key="plugin.tea.property.title"/>
</th>
</tr>
</thead>
<tbody>
<f:for each="{teas}" as="tea">
<tr>
<td>
{tea.uid}
</td>
<td>
<f:link.action action="show" arguments="{tea: tea}" pageUid="{settings.singleViewPageUid}">
{tea.title}
</f:link.action>
</td>
</tr>
</f:for>
</tbody>
</table>
</f:section>
</html>

View file

@ -0,0 +1,42 @@
<!DOCTYPE html>
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default"/>
<f:section name="main">
<h2>
<f:translate key="plugin.tea.heading"/>
</h2>
<f:translate key="plugin.tea.filter.rating"/>
<f:link.action action="filter" controller="Rating" arguments="{stars:1}">1</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:2}">2</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:3}">3</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:4}">4</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:5}">5</f:link.action>
<table class="table">
<thead>
<tr>
<th>
<f:translate key="plugin.tea.property.uid"/>
</th>
<th>
<f:translate key="plugin.tea.property.title"/>
</th>
</tr>
</thead>
<tbody>
<f:for each="{teas}" as="tea">
<tr>
<td>
{tea.uid}
</td>
<td>
<f:link.action pluginName="tearaing" action="show" arguments="{tea: tea}" pageUid="{settings.singleViewPageUid}">
{tea.title}
</f:link.action>
</td>
</tr>
</f:for>
</tbody>
</table>
</f:section>
</html>

View file

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default"/>
<f:section name="main">
<h2>
Rating Plugin: {tea.title}
</h2>
{tea.description -> f:format.html()}
</f:section>
</html>

View file

@ -6,11 +6,6 @@
<h2>
<f:translate key="plugin.tea.heading"/>
</h2>
<f:link.action action="filter" controller="Rating" arguments="{stars:1}">1</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:2}">2</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:3}">3</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:4}">4</f:link.action>
<f:link.action action="filter" controller="Rating" arguments="{tea:tea,stars:5}">5</f:link.action>
<table class="table">
<thead>
<tr>

View file

@ -18,7 +18,6 @@ ExtensionUtility::configurePlugin(
// all actions
[
TeaController::class => 'index',
RatingController::class => 'filter'
],
// non-cacheable actions
[
@ -45,13 +44,26 @@ ExtensionUtility::configurePlugin(
// all actions
[
FrontEndEditorController::class => 'index, edit, update, create, new, delete',
RatingController::class => 'filter,rating'
],
// non-cacheable actions
[
// All actions need to be non-cacheable because they either contain dynamic data,
// or because they are specific to the logged-in FE user (while FE content is cached by FE groups).
FrontEndEditorController::class => 'index, edit, update, create, new, delete',
RatingController::class => 'rating'
]
);
// Combine TeaController and RatingController into a new Plugin
ExtensionUtility::configurePlugin(
'Tea',
'TeaRating',
[
TeaController::class => 'index',
RatingController::class => 'filter,rating'
],
[
TeaController::class => 'index',
RatingController::class => 'rating,filter'
]
);