Commit 0efa3a2b authored by Gabe Troyan's avatar Gabe Troyan Committed by waldhacker
Browse files

[FEATURE] Add fragment option to Redirect Finisher

This patch adds a new field called "fragment" to the EXT:form Redirect
finisher. It will be appended to the redirect URL (e.g. #c127). The
fragment can be either a content element identifier or a custom fragment
such as `foo`.

Resolves: #83912
Releases: main
Change-Id: I724e378894782215cc7db21160daef930d0cfdb2
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73721

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Björn Jacob's avatarBjörn Jacob <bjoern.jacob@tritum.de>
Tested-by: Mathias Brodala's avatarMathias Brodala <mbrodala@pagemachine.de>
Tested-by: waldhacker's avatarwaldhacker <hello@waldhacker.dev>
Reviewed-by: Björn Jacob's avatarBjörn Jacob <bjoern.jacob@tritum.de>
Reviewed-by: Mathias Brodala's avatarMathias Brodala <mbrodala@pagemachine.de>
Reviewed-by: waldhacker's avatarwaldhacker <hello@waldhacker.dev>
parent 651bdca2
.. include:: /Includes.rst.txt
=======================================================
Feature: #83912 - Specify Section in Redirect Finisher
=======================================================
See :issue:`83912`
Description
===========
It is now possible to specify a fragment in the Redirect finisher. This
allows a user to be redirected to a specific content element or relevant
section after completing a form.
Impact
======
A section can be defined in a form definition with the `fragment` option.
In the example below, :yaml:`fragment: '9'` refers to the content element
with `uid` 9. There is no need to add the :html:`#` character. It is also
possible to configure a custom section, e.g. :yaml:`fragment: 'foo'`.
.. code-block:: yaml
finishers:
-
options:
pageUid: '7'
additionalParameters: ''
fragment: '9'
identifier: Redirect
.. index:: Backend, ext:form
......@@ -37,6 +37,7 @@ class RedirectFinisher extends AbstractFinisher
'pageUid' => 1,
'additionalParameters' => '',
'statusCode' => 303,
'fragment' => '',
];
/**
......@@ -66,9 +67,10 @@ class RedirectFinisher extends AbstractFinisher
$additionalParameters = is_string($additionalParameters) ? $additionalParameters : '';
$additionalParameters = '&' . ltrim($additionalParameters, '&');
$statusCode = (int)$this->parseOption('statusCode');
$fragment = (string)$this->parseOption('fragment');
$this->finisherContext->cancel();
$this->redirect($pageUid, $additionalParameters, $statusCode);
$this->redirect($pageUid, $additionalParameters, $fragment, $statusCode);
}
/**
......@@ -84,11 +86,12 @@ class RedirectFinisher extends AbstractFinisher
* @param int $statusCode (optional) The HTTP status code for the redirect. Default is "303 See Other
* @see forward()
*/
protected function redirect(int $pageUid = 1, string $additionalParameters = '', int $statusCode = 303)
protected function redirect(int $pageUid = 1, string $additionalParameters = '', string $fragment = '', int $statusCode = 303)
{
$typolinkConfiguration = [
'parameter' => $pageUid,
'additionalParams' => $additionalParameters,
'section' => $fragment,
];
$redirectUri = $this->getTypoScriptFrontendController()->cObj->createUrl($typolinkConfiguration);
$this->redirectToUri($redirectUri, $statusCode);
......
......@@ -13,6 +13,7 @@ TYPO3:
options:
pageUid: ''
additionalParameters: ''
fragment: ''
FormEngine:
label: tt_content.finishersDefinition.Redirect.label
elements:
......@@ -31,3 +32,7 @@ TYPO3:
label: tt_content.finishersDefinition.Redirect.additionalParameters.label
config:
type: input
fragment:
label: tt_content.finishersDefinition.Redirect.fragment.label
config:
type: input
......@@ -365,6 +365,15 @@ TYPO3:
templateName: Inspector-TextEditor
label: formEditor.elements.Form.finisher.Redirect.editor.additionalParameters.label
propertyPath: options.additionalParameters
400:
identifier: fragment
templateName: Inspector-Typo3WinBrowserEditor
label: formEditor.elements.Form.finisher.Redirect.editor.fragment.label
buttonLabel: formEditor.elements.Form.finisher.Redirect.editor.fragment.buttonLabel
browsableType: tt_content
iconIdentifier: mimetypes-x-content-text
propertyPath: options.fragment
fieldExplanationText: formEditor.elements.Form.finisher.Redirect.editor.fragment.fieldExplanationText
9999:
identifier: removeButton
templateName: Inspector-RemoveElementEditor
......
......@@ -747,6 +747,25 @@ additionalParameters
Additional parameters which should be used on the target page
.. _apireference-finisheroptions-redirectfinisher-options-fragment:
fragment
++++++++
:aspect:`Data type`
string
:aspect:`Mandatory`
No
:aspect:`Default value`
empty string
:aspect:`Description`
Add a fragment (e.g. `#c9` or `#foo`) to the redirect link.
The `#' character can be omitted.
.. _apireference-finisheroptions-redirectfinisher-options-delay:
delay
......
......@@ -101,6 +101,35 @@ options.additionalParameters
Additional parameters which should be used on the target page.
.. _typo3.cms.form.prototypes.<prototypeIdentifier>.finishersdefinition.redirect.options.fragment:
options.fragment
----------------
:aspect:`Option path`
TYPO3.CMS.Form.prototypes.<prototypeIdentifier>.finishersDefinition.Redirect.options.fragment
:aspect:`Data type`
string
:aspect:`Needed by`
Frontend
:aspect:`Mandatory`
No
:aspect:`Default value`
empty string
:aspect:`Good to know`
- :ref:`"Redirect finisher"<apireference-finisheroptions-redirectfinisher>`
- :ref:`"Accessing form runtime values"<concepts-finishers-customfinisherimplementations-accessingoptions-formruntimeaccessor>`
:aspect:`Description`
Add a fragment (e.g. `#c9` or `#foo`) to the redirect link.
The `#' character can be omitted.
.. _typo3.cms.form.prototypes.<prototypeIdentifier>.finishersdefinition.redirect.options.delay:
options.delay
......@@ -218,6 +247,7 @@ formeditor.iconIdentifier
options:
pageUid: ''
additionalParameters: ''
fragment: ''
.. :aspect:`Good to know`
ToDo
......@@ -256,6 +286,7 @@ formeditor.label
options:
pageUid: ''
additionalParameters: ''
fragment: ''
:aspect:`Good to know`
- :ref:`"Translate form editor settings"<concepts-formeditor-translation-formeditor>`
......@@ -294,6 +325,7 @@ formeditor.predefinedDefaults
options:
pageUid: ''
additionalParameters: ''
fragment: ''
.. :aspect:`Good to know`
ToDo
......@@ -376,6 +408,10 @@ FormEngine.elements
label: tt_content.finishersDefinition.Redirect.additionalParameters.label
config:
type: input
fragment:
label: tt_content.finishersDefinition.Redirect.fragment.label
config:
type: input
:aspect:`Good to know`
- :ref:`"Translate form plugin settings"<concepts-formplugin-translation-formengine>`
......
......@@ -255,6 +255,9 @@ Properties
.. _typo3.cms.form.prototypes.<prototypeIdentifier>.formelementsdefinition.form.formeditor.propertycollections.finishers.30.editors.300:
.. include:: Form/formEditor/propertyCollections/finishers/30/editors/300.rst
.. _typo3.cms.form.prototypes.<prototypeIdentifier>.formelementsdefinition.form.formeditor.propertycollections.finishers.30.editors.400:
.. include:: Form/formEditor/propertyCollections/finishers/30/editors/400.rst
.. _typo3.cms.form.prototypes.<prototypeIdentifier>.formelementsdefinition.form.formeditor.propertycollections.finishers.30.editors.9999:
.. include:: Form/formEditor/propertyCollections/finishers/30/editors/9999.rst
......
......@@ -375,6 +375,15 @@ formEditor
templateName: Inspector-TextEditor
label: formEditor.elements.Form.finisher.Redirect.editor.additionalParameters.label
propertyPath: options.additionalParameters
400:
identifier: fragment
templateName: Inspector-Typo3WinBrowserEditor
label: formEditor.elements.Form.finisher.Redirect.editor.fragment.label
buttonLabel: formEditor.elements.Form.finisher.Redirect.editor.fragment.buttonLabel
browsableType: tt_content
iconIdentifier: mimetypes-x-content-text
propertyPath: options.fragment
fieldExplanationText: formEditor.elements.Form.finisher.Redirect.editor.fragment.fieldExplanationText
9999:
identifier: removeButton
templateName: Inspector-RemoveElementEditor
......
......@@ -46,6 +46,15 @@ formEditor.propertyCollections.finishers.30
templateName: Inspector-TextEditor
label: formEditor.elements.Form.finisher.Redirect.editor.additionalParameters.label
propertyPath: options.additionalParameters
400:
identifier: fragment
templateName: Inspector-Typo3WinBrowserEditor
label: formEditor.elements.Form.finisher.Redirect.editor.fragment.label
buttonLabel: formEditor.elements.Form.finisher.Redirect.editor.fragment.buttonLabel
browsableType: tt_content
iconIdentifier: mimetypes-x-content-text
propertyPath: options.fragment
fieldExplanationText: formEditor.elements.Form.finisher.Redirect.editor.fragment.fieldExplanationText
9999:
identifier: removeButton
templateName: Inspector-RemoveElementEditor
......
.. include:: /Includes.rst.txt
formEditor.propertyCollections.finishers.30.editors.400
-------------------------------------------------------
:aspect:`Option path`
TYPO3.CMS.Form.prototypes.<prototypeIdentifier>.formElementsDefinition.Form.formEditor.propertyCollections.finishers.30.editors.400
:aspect:`Data type`
array/ :ref:`[TextEditor] <typo3.cms.form.prototypes.\<prototypeidentifier>.formelementsdefinition.\<formelementtypeidentifier>.formeditor.editors.*.texteditor>`
:aspect:`Needed by`
Backend (form editor)
:aspect:`Mandatory`
Recommended
:aspect:`Default value (for prototype 'standard')`
.. code-block:: yaml
:linenos:
:emphasize-lines: 8-
Form:
formEditor:
propertyCollections:
finishers:
30:
identifier: Redirect
editors:
400:
identifier: fragment
templateName: Inspector-Typo3WinBrowserEditor
label: formEditor.elements.Form.finisher.Redirect.editor.fragment.label
buttonLabel: formEditor.elements.Form.finisher.Redirect.editor.fragment.buttonLabel
browsableType: tt_content
iconIdentifier: mimetypes-x-content-text
propertyPath: options.fragment
fieldExplanationText: formEditor.elements.Form.finisher.Redirect.editor.fragment.fieldExplanationText
......@@ -163,6 +163,9 @@
<trans-unit id="tt_content.finishersDefinition.Redirect.additionalParameters.label" resname="tt_content.finishersDefinition.Redirect.additionalParameters.label" xml:space="preserve">
<source>Additional link parameter</source>
</trans-unit>
<trans-unit id="tt_content.finishersDefinition.Redirect.fragment.label" resname="tt_content.finishersDefinition.Redirect.fragment.label" xml:space="preserve">
<source>Add fragment to the redirect link</source>
</trans-unit>
<trans-unit id="formManagerController.deleteAction.error.title" resname="formManagerController.deleteAction.error.title" xml:space="preserve">
<source>Delete error</source>
......@@ -733,6 +736,15 @@
<trans-unit id="formEditor.elements.Form.finisher.Redirect.editor.additionalParameters.label" resname="formEditor.elements.Form.finisher.Redirect.editor.additionalParameters.label" xml:space="preserve">
<source>Additional parameters</source>
</trans-unit>
<trans-unit id="formEditor.elements.Form.finisher.Redirect.editor.fragment.label" resname="formEditor.elements.Form.finisher.Redirect.editor.fragment.label" xml:space="preserve">
<source>URL fragment</source>
</trans-unit>
<trans-unit id="formEditor.elements.Form.finisher.Redirect.editor.fragment.buttonLabel" resname="formEditor.elements.Form.finisher.Redirect.editor.fragment.buttonLabel" xml:space="preserve">
<source>Page Content</source>
</trans-unit>
<trans-unit id="formEditor.elements.Form.finisher.Redirect.editor.fragment.fieldExplanationText" resname="formEditor.elements.Form.finisher.Redirect.editor.fragment.fieldExplanationText" xml:space="preserve">
<source>You can use a content element identifier as URL fragment or set a custom fragment identifier.</source>
</trans-unit>
<trans-unit id="formEditor.elements.Form.finisher.DeleteUploads.editor.header.label" resname="formEditor.elements.Form.finisher.DeleteUploads.editor.header.label" xml:space="preserve">
<source>Delete uploads</source>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment