Skip to content

Commit 58f3a58

Browse files
authored
[TASK] Add example: Display an Extbase plugin in a Fluid template (#1345)
* [TASK] Add example: Display an Extbase plugin in a Fluid template Releases: main, 12.4 * [TASK] Add example: Display an Extbase plugin in a Fluid template Releases: main, 12.4 * [TASK] Add example: Display an Extbase plugin in a Fluid template Releases: main, 12.4 * Use $contentObject->data * Update Documentation/ContentObjects/Extbaseplugin/Index.rst
1 parent a341f65 commit 58f3a58

File tree

5 files changed

+87
-2
lines changed

5 files changed

+87
-2
lines changed

Documentation/ContentObjects/Extbaseplugin/Index.rst

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ Properties
5252

5353
.. _cobj-extbaseplugin-examples:
5454

55-
Example
56-
=======
55+
Example: Display an Extbase plugin via TypoScript
56+
=================================================
5757

5858
.. code-block:: typoscript
5959
:caption: EXT:my_extension/Configuration/TypoScript/setup.typoscript
@@ -62,6 +62,43 @@ Example
6262
page.10.extensionName = MyExtension
6363
page.10.pluginName = MyPlugin
6464
65+
.. _cobj-extbaseplugin-examples-fluid:
66+
67+
Example: Display an Extbase plugin in a Fluid template
68+
======================================================
69+
70+
It is possible to display an Extbase plugin in Fluid using the
71+
:ref:`CObject ViewHelper <f:cObject> <t3viewhelper:typo3-fluid-cobject>`:
72+
73+
.. literalinclude:: _CodeSnippets/_SomeTemplate.html
74+
:caption: EXT:my_extension/Resources/Private/Templates/Pages/SomeTemplate.html
75+
76+
Create a lib object which utilizes the :typoscript:`EXTBASEPLUGIN` into
77+
a :typoscript:`lib` object:
78+
79+
.. literalinclude:: _CodeSnippets/_libMyPlugin.typoscript
80+
:caption: EXT:my_extension/Configuration/TypoScript/setup.typoscript
81+
82+
For `extensionName` and `pluginName` use the names as configured in
83+
:php:`\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin()`:
84+
85+
.. literalinclude:: _CodeSnippets/_configurePlugin.php
86+
:caption: EXT:my_extension/ext_localconf.php
87+
:emphasize-lines: 9,10
88+
89+
If you passed data to the ViewHelper, you can access the data in the controller's
90+
action by getting the currentContentObject from the request:
91+
92+
.. literalinclude:: _CodeSnippets/_MyController.php
93+
:caption: EXT:my_extension/Classes/Controller/MyController.php
94+
:emphasize-lines: 16,17
95+
96+
.. note::
97+
You should treat all data from the
98+
:php-short:`\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer` as
99+
potential user input. Do not use it unescaped and do not trust to receive
100+
certain types.
101+
65102
.. _cobj-extbaseplugin-history:
66103

67104
History
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MyVendor\MyExtension\Controller;
6+
7+
use Psr\Http\Message\ResponseInterface;
8+
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
9+
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
10+
11+
class MyController extends ActionController
12+
{
13+
public function listAction(): ResponseInterface
14+
{
15+
/** @var ContentObjectRenderer $contentObject */
16+
$contentObject = $this->request->getAttribute('currentContentObject');
17+
$dataFromTypoScript = $contentObject->data;
18+
$someValue = (int)($dataFromTypoScript['someValue'] ?? 0);
19+
$someSetting = $dataFromTypoScript['someSetting'] ?? '';
20+
// Do something
21+
return $this->htmlResponse();
22+
}
23+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!-- ... -->
2+
<f:cObject
3+
typoscriptObjectPath="lib.myPlugin"
4+
data="{someValue: page.pageRecord.someValue, someSetting: site.someSetting}"
5+
/>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
use MyVendor\MyExtension\Controller\MyController;
4+
use TYPO3\CMS\Extbase\Utility\ExtensionUtility;
5+
6+
defined('TYPO3') || die('Access denied.');
7+
8+
ExtensionUtility::configurePlugin(
9+
'MyExtension',
10+
'MyPlugIn1',
11+
[MyController::class => 'list, show'],
12+
[],
13+
ExtensionUtility::PLUGIN_TYPE_CONTENT_ELEMENT,
14+
);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
lib.myPlugin = EXTBASEPLUGIN
2+
lib.myPlugin {
3+
extensionName = MyExtension
4+
pluginName = MyPlugIn1
5+
settings.detailPid = 42
6+
}

0 commit comments

Comments
 (0)