Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 12.4] [TASK] Check request object in conditions #808

Merged
merged 1 commit into from
Sep 30, 2023
Merged
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
37 changes: 27 additions & 10 deletions Documentation/Conditions/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,16 @@ traverse()
:caption: EXT:site_package/Configuration/TypoScript/setup.typoscript

# Traverse query parameters of current request along tx_news_pi1[news]
[traverse(request.getQueryParams(), 'tx_news_pi1/news') > 0]
[request && traverse(request.getQueryParams(), 'tx_news_pi1/news') > 0]

.. tip::
Checking for the :ref:`request object <t3coreapi:typo3-request>` to be
available before using :typoscript:`traverse()` may be necessary, for
example, when using :ref:`Extbase <t3coreapi:extbase>` repositories in
:ref:`CLI <t3coreapi:symfony-console-commands>` context (as Extbase
depends on TypoScript and on the command line is no request object
available). This avoids the error
`Unable to call method "getQueryParams" of non-object "request"`.

.. index:: Conditions; compatVersion
.. _condition-function-compatVersion:
Expand Down Expand Up @@ -1087,6 +1095,15 @@ request()
:aspect:`Description`
Allows to fetch information from current request.

.. tip::
Checking for the :ref:`request object <t3coreapi:typo3-request>` before
using in a condition may be necessary, for example, when using
:ref:`Extbase <t3coreapi:extbase>` repositories in
:ref:`CLI <t3coreapi:symfony-console-commands>` context (as Extbase
depends on TypoScript and on the command line is no request object
available). This avoids, for example, the error
`Unable to call method "getQueryParams" of non-object "request"`.


.. index:: Conditions; request.getQueryParams()
.. _condition-function-request-getQueryParams():
Expand Down Expand Up @@ -1126,7 +1143,7 @@ request.getQueryParams()
# Safely check the query parameter array to avoid error logs in case key
# is not defined. This will check if the GET parameter
# tx_news_pi1[news] in the URL is greater than 0:
[traverse(request.getQueryParams(), 'tx_news_pi1/news') > 0]
[request && traverse(request.getQueryParams(), 'tx_news_pi1/news') > 0]


.. index:: Conditions; request.getParsedBody()
Expand All @@ -1152,7 +1169,7 @@ request.getParsedBody()
.. code-block:: typoscript
:caption: EXT:site_package/Configuration/TypoScript/setup.typoscript

[request.getParsedBody()['foo'] == 1]
[request && request.getParsedBody()['foo'] == 1]


.. index:: Conditions; request.getHeaders()
Expand All @@ -1177,11 +1194,11 @@ request.getHeaders()
.. code-block:: typoscript
:caption: EXT:site_package/Configuration/TypoScript/setup.typoscript

[request.getHeaders()['Accept'] == 'json']
[request && request.getHeaders()['Accept'] == 'json']
page.10.value = Accepts json
[END]

[request.getHeaders()['host'][0] == 'www.example.org']
[request && request.getHeaders()['host'][0] == 'www.example.org']
page.20.value = The host is www.example.org
[END]

Expand All @@ -1208,7 +1225,7 @@ request.getCookieParams()
.. code-block:: typoscript
:caption: EXT:site_package/Configuration/TypoScript/setup.typoscript

[request.getCookieParams()['foo'] == 1]
[request && request.getCookieParams()['foo'] == 1]


.. index:: Conditions; request.getNormalizedParams()
Expand Down Expand Up @@ -1236,11 +1253,11 @@ request.getNormalizedParams()
.. code-block:: typoscript
:caption: EXT:site_package/Configuration/TypoScript/setup.typoscript

[request.getNormalizedParams().isHttps()]
[request && request.getNormalizedParams().isHttps()]
page.10.value = HTTPS is being used
[END]

[request.getNormalizedParams().getHttpHost() == "example.org"]
[request && request.getNormalizedParams().getHttpHost() == "example.org"]
page.10.value = The host is "example.org"
[END]

Expand Down Expand Up @@ -1269,10 +1286,10 @@ request.getPageArguments()
.. code-block:: typoscript
:caption: EXT:site_package/Configuration/TypoScript/setup.typoscript

[request.getPageArguments().get('foo_id') > 0]
[request && request.getPageArguments().get('foo_id') > 0]

# True, if current page type is 98
[request.getPageArguments()?.getPageType() == 98]
[request && request.getPageArguments()?.getPageType() == 98]


.. index:: Conditions; session
Expand Down
Loading