From 10c1ef57481d17143ccbbf5100616be1144a12a6 Mon Sep 17 00:00:00 2001 From: "lina.wolf" Date: Fri, 27 Sep 2024 12:55:00 +0200 Subject: [PATCH 1/5] [TASK] Add example: Display an Extbase plugin in a Fluid template Releases: main, 12.4 --- .../ContentObjects/Extbaseplugin/Index.rst | 40 ++++++++++++++++++- .../_CodeSnippets/_MyController.php | 25 ++++++++++++ .../_CodeSnippets/_SomeTemplate.html | 7 ++++ .../_CodeSnippets/_configurePlugin.php | 14 +++++++ .../_CodeSnippets/_libMyPlugin.typoscript | 6 +++ 5 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_MyController.php create mode 100644 Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_SomeTemplate.html create mode 100644 Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_configurePlugin.php create mode 100644 Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_libMyPlugin.typoscript diff --git a/Documentation/ContentObjects/Extbaseplugin/Index.rst b/Documentation/ContentObjects/Extbaseplugin/Index.rst index a22b04f50..359a7c75e 100644 --- a/Documentation/ContentObjects/Extbaseplugin/Index.rst +++ b/Documentation/ContentObjects/Extbaseplugin/Index.rst @@ -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 @@ -62,6 +62,42 @@ 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 within Fluid using the +:ref:`CObject ViewHelper `: + +.. literalinclude:: _CodeSnippets/_SomeTemplate.html + :caption: EXT:myExtension/Configuration/TypoScript/setup.typoscript + +Save the :typoscript:`EXTBASEPLUGIN` into a :typoscript:`lib` object: + +.. literalinclude:: _CodeSnippets/_libMyPlugin.typoscript + :caption: EXT:myExtension/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:myExtension/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:myExtension/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 diff --git a/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_MyController.php b/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_MyController.php new file mode 100644 index 000000000..4d65aad73 --- /dev/null +++ b/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_MyController.php @@ -0,0 +1,25 @@ +request->getAttribute('currentContentObject'); + $dataFromTypoScript = $contentObject->getCurrentVal(); + if (is_array($dataFromTypoScript)) { + $someValue = (int)($dataFromTypoScript['someValue'] ?? 0); + $someSetting = $dataFromTypoScript['someSetting'] ?? ''; + // Do something + } + return $this->htmlResponse(); + } +} diff --git a/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_SomeTemplate.html b/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_SomeTemplate.html new file mode 100644 index 000000000..2a92e3e01 --- /dev/null +++ b/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_SomeTemplate.html @@ -0,0 +1,7 @@ + + + + diff --git a/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_configurePlugin.php b/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_configurePlugin.php new file mode 100644 index 000000000..bcd9da7eb --- /dev/null +++ b/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_configurePlugin.php @@ -0,0 +1,14 @@ + 'list, show'], + [], + ExtensionUtility::PLUGIN_TYPE_CONTENT_ELEMENT, +); diff --git a/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_libMyPlugin.typoscript b/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_libMyPlugin.typoscript new file mode 100644 index 000000000..cbea150d7 --- /dev/null +++ b/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_libMyPlugin.typoscript @@ -0,0 +1,6 @@ +lib.myPlugin = EXTBASEPLUGIN +lib.myPlugin { + extensionName = MyExtension + pluginName = MyPlugIn1 + settings.detailPid = 42 +} From 0d847594868f1c640b03ca1f829b3892294ba58a Mon Sep 17 00:00:00 2001 From: "lina.wolf" Date: Sat, 28 Sep 2024 06:25:40 +0200 Subject: [PATCH 2/5] [TASK] Add example: Display an Extbase plugin in a Fluid template Releases: main, 12.4 --- .../ContentObjects/Extbaseplugin/Index.rst | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Documentation/ContentObjects/Extbaseplugin/Index.rst b/Documentation/ContentObjects/Extbaseplugin/Index.rst index 359a7c75e..bbf780b6e 100644 --- a/Documentation/ContentObjects/Extbaseplugin/Index.rst +++ b/Documentation/ContentObjects/Extbaseplugin/Index.rst @@ -67,29 +67,30 @@ Example: Display an Extbase plugin via TypoScript Example: Display an Extbase plugin in a Fluid template ====================================================== -It is possible to display an Extbase plugin in within Fluid using the +It is possible to display an Extbase plugin in Fluid using the :ref:`CObject ViewHelper `: .. literalinclude:: _CodeSnippets/_SomeTemplate.html - :caption: EXT:myExtension/Configuration/TypoScript/setup.typoscript + :caption: EXT:my_extension/Configuration/TypoScript/setup.typoscript -Save the :typoscript:`EXTBASEPLUGIN` into a :typoscript:`lib` object: +Create a lib object which utilizes the :typoscript:`EXTBASEPLUGIN` into +a :typoscript:`lib` object: .. literalinclude:: _CodeSnippets/_libMyPlugin.typoscript - :caption: EXT:myExtension/Configuration/TypoScript/setup.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:myExtension/ext_localconf.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:myExtension/Classes/Controller/MyController.php + :caption: EXT:my_extension/Classes/Controller/MyController.php :emphasize-lines: 16,17 .. note:: From 20adfb9d26a6ba02871fc3344e866643b71678af Mon Sep 17 00:00:00 2001 From: "lina.wolf" Date: Sat, 28 Sep 2024 06:26:42 +0200 Subject: [PATCH 3/5] [TASK] Add example: Display an Extbase plugin in a Fluid template Releases: main, 12.4 --- .../Extbaseplugin/_CodeSnippets/_SomeTemplate.html | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_SomeTemplate.html b/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_SomeTemplate.html index 2a92e3e01..98e5d30e3 100644 --- a/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_SomeTemplate.html +++ b/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_SomeTemplate.html @@ -1,7 +1,5 @@ - - - + From 9a205dd512b40ec5e99ec7872cff33248683ac1d Mon Sep 17 00:00:00 2001 From: "lina.wolf" Date: Thu, 3 Oct 2024 17:06:02 +0200 Subject: [PATCH 4/5] Use $contentObject->data --- .../Extbaseplugin/_CodeSnippets/_MyController.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_MyController.php b/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_MyController.php index 4d65aad73..a2ef3c794 100644 --- a/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_MyController.php +++ b/Documentation/ContentObjects/Extbaseplugin/_CodeSnippets/_MyController.php @@ -14,12 +14,10 @@ public function listAction(): ResponseInterface { /** @var ContentObjectRenderer $contentObject */ $contentObject = $this->request->getAttribute('currentContentObject'); - $dataFromTypoScript = $contentObject->getCurrentVal(); - if (is_array($dataFromTypoScript)) { - $someValue = (int)($dataFromTypoScript['someValue'] ?? 0); - $someSetting = $dataFromTypoScript['someSetting'] ?? ''; - // Do something - } + $dataFromTypoScript = $contentObject->data; + $someValue = (int)($dataFromTypoScript['someValue'] ?? 0); + $someSetting = $dataFromTypoScript['someSetting'] ?? ''; + // Do something return $this->htmlResponse(); } } From dd8fbf031e8c7389ff3ed1a49264c9db61daeeb2 Mon Sep 17 00:00:00 2001 From: Lina Wolf <48202465+linawolf@users.noreply.github.com> Date: Sun, 6 Oct 2024 19:18:46 +0200 Subject: [PATCH 5/5] Update Documentation/ContentObjects/Extbaseplugin/Index.rst --- Documentation/ContentObjects/Extbaseplugin/Index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/ContentObjects/Extbaseplugin/Index.rst b/Documentation/ContentObjects/Extbaseplugin/Index.rst index bbf780b6e..1953d5074 100644 --- a/Documentation/ContentObjects/Extbaseplugin/Index.rst +++ b/Documentation/ContentObjects/Extbaseplugin/Index.rst @@ -71,7 +71,7 @@ It is possible to display an Extbase plugin in Fluid using the :ref:`CObject ViewHelper `: .. literalinclude:: _CodeSnippets/_SomeTemplate.html - :caption: EXT:my_extension/Configuration/TypoScript/setup.typoscript + :caption: EXT:my_extension/Resources/Private/Templates/Pages/SomeTemplate.html Create a lib object which utilizes the :typoscript:`EXTBASEPLUGIN` into a :typoscript:`lib` object: