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
41 changes: 39 additions & 2 deletions Documentation/ContentObjects/Extbaseplugin/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Properties

.. _cobj-extbaseplugin-examples:

Example
=======
Example: Display an Extbase plugin via TypoScript
=================================================

.. code-block:: typoscript
:caption: EXT:my_extension/Configuration/TypoScript/setup.typoscript
Expand All @@ -62,6 +62,43 @@ Example
page.10.extensionName = MyExtension
page.10.pluginName = MyPlugin

.. _cobj-extbaseplugin-examples-fluid:

Example: Display an Extbase plugin in a Fluid template
======================================================

It is possible to display an Extbase plugin in Fluid using the
:ref:`CObject ViewHelper <f:cObject> <t3viewhelper:typo3-fluid-cobject>`:

.. literalinclude:: _CodeSnippets/_SomeTemplate.html
:caption: EXT:my_extension/Resources/Private/Templates/Pages/SomeTemplate.html

Create a lib object which utilizes the :typoscript:`EXTBASEPLUGIN` into
a :typoscript:`lib` object:

.. literalinclude:: _CodeSnippets/_libMyPlugin.typoscript
:caption: EXT:my_extension/Configuration/TypoScript/setup.typoscript

For `extensionName` and `pluginName` use the names as configured in
:php:`\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin()`:

.. literalinclude:: _CodeSnippets/_configurePlugin.php
:caption: EXT:my_extension/ext_localconf.php
:emphasize-lines: 9,10

If you passed data to the ViewHelper, you can access the data in the controller's
action by getting the currentContentObject from the request:

.. literalinclude:: _CodeSnippets/_MyController.php
:caption: EXT:my_extension/Classes/Controller/MyController.php
:emphasize-lines: 16,17

.. note::
You should treat all data from the
:php-short:`\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer` as
potential user input. Do not use it unescaped and do not trust to receive
certain types.

.. _cobj-extbaseplugin-history:

History
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Controller;

use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

class MyController extends ActionController
{
public function listAction(): ResponseInterface
{
/** @var ContentObjectRenderer $contentObject */
$contentObject = $this->request->getAttribute('currentContentObject');
$dataFromTypoScript = $contentObject->data;
$someValue = (int)($dataFromTypoScript['someValue'] ?? 0);
$someSetting = $dataFromTypoScript['someSetting'] ?? '';
// Do something
return $this->htmlResponse();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- ... -->
<f:cObject
typoscriptObjectPath="lib.myPlugin"
data="{someValue: page.pageRecord.someValue, someSetting: site.someSetting}"
/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use MyVendor\MyExtension\Controller\MyController;
use TYPO3\CMS\Extbase\Utility\ExtensionUtility;

defined('TYPO3') || die('Access denied.');

ExtensionUtility::configurePlugin(
'MyExtension',
'MyPlugIn1',
[MyController::class => 'list, show'],
[],
ExtensionUtility::PLUGIN_TYPE_CONTENT_ELEMENT,
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
lib.myPlugin = EXTBASEPLUGIN
lib.myPlugin {
extensionName = MyExtension
pluginName = MyPlugIn1
settings.detailPid = 42
}
Loading