Skip to content

Commit cf89525

Browse files
authored
[TASK] Accessing site settings in Extbase (#6284)
* [TASK] Accessing site settings in Extbase Releases: main, 13.4 * Apply suggestion from @linawolf
1 parent 897d4cf commit cf89525

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
lines changed

Documentation/ApiOverview/SiteHandling/AccessingSiteConfiguration.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ PHP API: accessing site configuration
1010
.. contents::
1111
:local:
1212

13-
Introduction
14-
============
15-
1613
The PHP API for sites comes in two parts:
1714

1815
- Accessing the current, resolved site object
@@ -27,6 +24,7 @@ current request but based on a page ID or a site identifier.
2724

2825
Let us look at both cases in detail.
2926

27+
.. _sitehandling-php-api-access:
3028

3129
Accessing the current site object
3230
=================================
@@ -114,6 +112,7 @@ API
114112

115113
.. include:: /CodeSnippets/Manual/Entity/SiteLanguage.rst.txt
116114

115+
.. _sitehandling-sitesetting-object:
117116

118117
The :php:`SiteSettings` object
119118
==============================

Documentation/ApiOverview/SiteHandling/SiteSettings.rst

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
Site settings
77
=============
88

9+
.. contents:: Table of contents
10+
911
.. versionadded:: 13.1
1012
Site settings can receive a type, a default value and some documentation in
1113
:ref:`site settings definitions <site-sets-settings-definition>`. It is
@@ -78,11 +80,42 @@ Add settings to the :file:`settings.yaml <set-settings-yaml>`:
7880
:yaml:`categoryPid`.
7981

8082

81-
.. index:: Site handling; TypoScript access to settings
8283
.. _sitehandling-settings-access:
8384

85+
Accessing site settings
86+
=======================
87+
88+
In PHP you can access the :php-short:`\TYPO3\CMS\Core\Site\Entity\SiteSettings`
89+
from the :php-short:`\TYPO3\CMS\Core\Site\Entity\Site` object via
90+
`getSettings()`. (See
91+
`Accessing the current site object <https://docs.typo3.org/permalink/t3coreapi:sitehandling-php-api-access>`_).
92+
93+
.. _sitehandling-settings-access-extbase-fluid:
94+
95+
Site settings in Extbase Fluid plugins
96+
--------------------------------------
97+
98+
At the time of writing site settings are not available in Extbase controllers or
99+
plugins unless they have been passed on to the plugin settings via TypoScript
100+
or made available in the controller.
101+
102+
To make the site settings available to all templates in your controller
103+
you can override method `AbstractController::initializeView()` and assign
104+
the site to the view:
105+
106+
.. literalinclude:: _Settings/_ExampleController.php
107+
:caption: EXT:myvendor/my-extension/Classes/Controller/ExampleController
108+
109+
You can then use the variable `{site.settings}` to access the site settings:
110+
111+
.. literalinclude:: _Settings/_ExampleControllerIndex.html
112+
:caption: EXT:myvendor/my-extension/Resources/Private/Templates/Example/Index.html
113+
114+
.. index:: Site handling; TypoScript access to settings
115+
.. _sitehandling-settings-access-typoscript:
116+
84117
Accessing site settings in page TSconfig or TypoScript
85-
======================================================
118+
------------------------------------------------------
86119

87120
.. code-block:: typoscript
88121
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Psr\Http\Message\ResponseInterface;
6+
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
7+
8+
class ExampleController extends ActionController
9+
{
10+
public function initializeView(): void
11+
{
12+
$this->view->assignMultiple([
13+
'site' => $this->request->getAttribute('site'),
14+
]);
15+
}
16+
public function indexAction(): ResponseInterface
17+
{
18+
// Variable '{site}' is automatically available
19+
return $this->htmlResponse();
20+
}
21+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<f:debug>{site.settings.mywebsite.example}</f:debug>

0 commit comments

Comments
 (0)