mirror of
https://github.com/FriendsOfTYPO3/tea.git
synced 2024-12-22 13:06:11 +01:00
[FEATURE] Tea plugin with TeaController and index action (#19)
This commit is contained in:
parent
e35a1c288a
commit
436a10b9d6
14 changed files with 264 additions and 0 deletions
37
Classes/Controller/TeaController.php
Normal file
37
Classes/Controller/TeaController.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
declare(strict_types = 1);
|
||||
namespace OliverKlee\Tea\Controller;
|
||||
|
||||
use OliverKlee\Tea\Domain\Repository\Product\TeaRepository;
|
||||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||
|
||||
/**
|
||||
* Controller for the main "Tea" FE plugin.
|
||||
*
|
||||
* @author Oliver Klee <typo3-coding@oliverklee.de
|
||||
*/
|
||||
class TeaController extends ActionController
|
||||
{
|
||||
/**
|
||||
* @var TeaRepository
|
||||
*/
|
||||
private $teaRepository = null;
|
||||
|
||||
/**
|
||||
* @param TeaRepository $teaRepository
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function injectTeaRepository(TeaRepository $teaRepository)
|
||||
{
|
||||
$this->teaRepository = $teaRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$this->view->assign('teas', $this->teaRepository->findAll());
|
||||
}
|
||||
}
|
35
Configuration/FlexForms/Plugin.xml
Normal file
35
Configuration/FlexForms/Plugin.xml
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<T3DataStructure>
|
||||
<sheets>
|
||||
<general>
|
||||
<ROOT>
|
||||
<TCEforms>
|
||||
<!--
|
||||
The sheet title will not be visible in the BE. Still, the XML element needs to be present to
|
||||
avoid a crash in the BE.
|
||||
-->
|
||||
<sheetTitle/>
|
||||
</TCEforms>
|
||||
<type>array</type>
|
||||
<el>
|
||||
<switchableControllerActions>
|
||||
<TCEforms>
|
||||
<label>LLL:EXT:tea/Resources/Private/Language/locallang.xlf:plugin.tea.view</label>
|
||||
<onChange>reload</onChange>
|
||||
<config>
|
||||
<type>select</type>
|
||||
<renderType>selectSingle</renderType>
|
||||
<items type="array">
|
||||
<numIndex index="1" type="array">
|
||||
<numIndex index="0">LLL:EXT:tea/Resources/Private/Language/locallang.xlf:plugin.tea.index</numIndex>
|
||||
<numIndex index="1">Tea->index</numIndex>
|
||||
</numIndex>
|
||||
</items>
|
||||
</config>
|
||||
</TCEforms>
|
||||
</switchableControllerActions>
|
||||
</el>
|
||||
</ROOT>
|
||||
</general>
|
||||
</sheets>
|
||||
</T3DataStructure>
|
23
Configuration/TCA/Overrides/tt_content.php
Normal file
23
Configuration/TCA/Overrides/tt_content.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
defined('TYPO3_MODE') or die();
|
||||
|
||||
// This makes the plugin selectable in the BE.
|
||||
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
|
||||
// extension name, exactly matching the PHP namespaces (vendor and product)
|
||||
'OliverKlee.Tea',
|
||||
// arbitrary, but unique plugin name (not visible in the BE)
|
||||
'Tea',
|
||||
// plugin title, as visible in the drop-down in the BE
|
||||
'LLL:EXT:tea/Resources/Private/Language/locallang.xlf:plugin.tea',
|
||||
// the icon visible in the drop-down in the BE
|
||||
'EXT:tea/Resources/Public/Icons/Extension.svg'
|
||||
);
|
||||
|
||||
// This removes the default controls from the plugin.
|
||||
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist']['tea_tea'] = 'recursive,select_key,pages';
|
||||
// These two commands add the flexform configuration for the plugin.
|
||||
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['tea_tea'] = 'pi_flexform';
|
||||
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue(
|
||||
'tea_tea',
|
||||
'FILE:EXT:tea/Configuration/FlexForms/Plugin.xml'
|
||||
);
|
24
Resources/Private/Language/de.locallang.xlf
Normal file
24
Resources/Private/Language/de.locallang.xlf
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
|
||||
<xliff version="1.0">
|
||||
<file source-language="en" target-language="de" datatype="plaintext" original="messages">
|
||||
<header/>
|
||||
<body>
|
||||
<trans-unit id="plugin.tea">
|
||||
<source>Tea</source>
|
||||
<target>Tee</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="plugin.tea.view">
|
||||
<source>View</source>
|
||||
<target>Ansicht</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="plugin.tea.index">
|
||||
<source>Tea list</source>
|
||||
<target>Teeliste</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="index.heading">
|
||||
<source>Our selection of assorted teas</source>
|
||||
<target>Unsere Auswahl an erlesenen Tees</target>
|
||||
</trans-unit>
|
||||
</body>
|
||||
</file>
|
||||
</xliff>
|
20
Resources/Private/Language/locallang.xlf
Normal file
20
Resources/Private/Language/locallang.xlf
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
|
||||
<xliff version="1.0">
|
||||
<file source-language="en" datatype="plaintext" original="messages">
|
||||
<header/>
|
||||
<body>
|
||||
<trans-unit id="plugin.tea">
|
||||
<source>Tea</source>
|
||||
</trans-unit>
|
||||
<trans-unit id="plugin.tea.view">
|
||||
<source>View</source>
|
||||
</trans-unit>
|
||||
<trans-unit id="plugin.tea.index">
|
||||
<source>Tea list</source>
|
||||
</trans-unit>
|
||||
<trans-unit id="index.heading">
|
||||
<source>Our selection of assorted teas</source>
|
||||
</trans-unit>
|
||||
</body>
|
||||
</file>
|
||||
</xliff>
|
5
Resources/Private/Layouts/Default.html
Normal file
5
Resources/Private/Layouts/Default.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
<html xmlns:f="https://xsd.helhum.io/ns/typo3/cms-fluid/master/ViewHelpers" data-namespace-typo3-fluid="true">
|
||||
<div class="tx-tea">
|
||||
<f:render section="main"/>
|
||||
</div>
|
||||
</html>
|
25
Resources/Private/Templates/Tea/Index.html
Normal file
25
Resources/Private/Templates/Tea/Index.html
Normal file
|
@ -0,0 +1,25 @@
|
|||
<!DOCTYPE html>
|
||||
<html xmlns:f="https://xsd.helhum.io/ns/typo3/cms-fluid/master/ViewHelpers" data-namespace-typo3-fluid="true">
|
||||
<f:layout name="Default"/>
|
||||
|
||||
<f:section name="main">
|
||||
<h2>
|
||||
<f:translate key="index.heading"/>
|
||||
</h2>
|
||||
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<f:for each="{teas}" as="tea">
|
||||
<tr>
|
||||
<td scope="row">
|
||||
{tea.uid}
|
||||
</td>
|
||||
<td>
|
||||
{tea.title}
|
||||
</td>
|
||||
</tr>
|
||||
</f:for>
|
||||
</tbody>
|
||||
</table>
|
||||
</f:section>
|
||||
</html>
|
79
Tests/Unit/Controller/TeaControllerTest.php
Normal file
79
Tests/Unit/Controller/TeaControllerTest.php
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
declare(strict_types = 1);
|
||||
namespace OliverKlee\Tea\Tests\Unit\Controller;
|
||||
|
||||
use Nimut\TestingFramework\TestCase\UnitTestCase;
|
||||
use OliverKlee\Tea\Controller\TeaController;
|
||||
use OliverKlee\Tea\Domain\Repository\Product\TeaRepository;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Prophecy\Prophecy\ProphecySubjectInterface;
|
||||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||
use TYPO3\CMS\Extbase\Mvc\View\JsonView;
|
||||
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
|
||||
use TYPO3\CMS\Fluid\View\TemplateView;
|
||||
|
||||
/**
|
||||
* Test case.
|
||||
*
|
||||
* @author Oliver Klee <typo3-coding@oliverklee.de
|
||||
*/
|
||||
class TeaControllerTest extends UnitTestCase
|
||||
{
|
||||
/**
|
||||
* @var TeaController
|
||||
*/
|
||||
private $subject = null;
|
||||
|
||||
/**
|
||||
* @var JsonView|ObjectProphecy
|
||||
*/
|
||||
private $viewProphecy = null;
|
||||
|
||||
/**
|
||||
* @var JsonView|ProphecySubjectInterface
|
||||
*/
|
||||
private $view = null;
|
||||
|
||||
/**
|
||||
* @var TeaRepository|ObjectProphecy
|
||||
*/
|
||||
private $teaRepositoryProphecy = null;
|
||||
|
||||
/**
|
||||
* @var TeaRepository|ProphecySubjectInterface
|
||||
*/
|
||||
private $teaRepository = null;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->subject = new TeaController();
|
||||
|
||||
$this->viewProphecy = $this->prophesize(TemplateView::class);
|
||||
$this->view = $this->viewProphecy->reveal();
|
||||
$this->inject($this->subject, 'view', $this->view);
|
||||
|
||||
$this->teaRepositoryProphecy = $this->prophesize(TeaRepository::class);
|
||||
$this->teaRepository = $this->teaRepositoryProphecy->reveal();
|
||||
$this->subject->injectTeaRepository($this->teaRepository);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function isActionController()
|
||||
{
|
||||
static::assertInstanceOf(ActionController::class, $this->subject);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function indexActionAssignsAllTeaAsTeasToView()
|
||||
{
|
||||
$teas = $this->prophesize(QueryResultInterface::class)->reveal();
|
||||
$this->teaRepositoryProphecy->findAll()->willReturn($teas);
|
||||
$this->viewProphecy->assign('teas', $teas)->shouldBeCalled();
|
||||
|
||||
$this->subject->indexAction();
|
||||
}
|
||||
}
|
16
ext_localconf.php
Normal file
16
ext_localconf.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
// This makes the plugin available for front-end rendering.
|
||||
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
|
||||
// extension name, exactly matching the PHP namespaces (vendor and product)
|
||||
'OliverKlee.Tea',
|
||||
// arbitrary, but unique plugin name (not visible in the BE)
|
||||
'Tea',
|
||||
// all actions
|
||||
[
|
||||
'Tea' => 'index',
|
||||
],
|
||||
// non-cacheable actions
|
||||
[
|
||||
'Tea' => '',
|
||||
]
|
||||
);
|
Loading…
Reference in a new issue