Skip to content

Commit

Permalink
FEATURE: Introduce routingArguments and queryParameters to Fusion…
Browse files Browse the repository at this point in the history
… link prototypes to replace `arguments` and `additionalParams`

The Fusion prototype `Neos.Fusion:ActionUri` has two additional properties:

- :routingArguments: (array) That are handled by the router
- :queryParameters: (array) Query parameters that are appended after routing

Those will eventually replace the properties `arguments` and `additionalParams` which are deprecated and will be removed with Neos 9.

The Fusion prototypes `Neos.Fusion:NodeUri` and `Neos.Fusion:NodeLink` have one additional property:

- :queryParameters: (array) Query parameters that are appended after routing

This will eventually replace the property `additionalParams` which is deprecated and will be removed with Neos 9.

Also this pr deprecates the fusion properties `addQueryString` and `argumentsToBeExcludedFromQueryString` from the `Neos.Fusion:ActionUri`, `Neos.Neos:NodeUri`, and `Neos.Neos:NodeLink`.
  • Loading branch information
mficzel committed Oct 7, 2022
1 parent a65cfc4 commit a707730
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 17 deletions.
41 changes: 37 additions & 4 deletions Neos.Fusion/Classes/FusionObjects/ActionUriImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* source code.
*/

use GuzzleHttp\Psr7\Uri;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\Routing\UriBuilder;

Expand Down Expand Up @@ -85,12 +86,24 @@ public function getAction(): ?string
return $this->fusionValue('action');
}

/**
* Controller arguments that are to be handled by the router
*
* @return array
*/
public function getRoutingArguments(): array
{
$arguments = $this->fusionValue('routingArguments');
return is_array($arguments) ? $arguments: [];
}

/**
* Controller arguments
*
* @return array|null
* @return array
* @deprecated to be removed with Neos 9
*/
public function getArguments(): ?array
public function getArguments(): array
{
$arguments = $this->fusionValue('arguments');
return is_array($arguments) ? $arguments: [];
Expand Down Expand Up @@ -120,16 +133,28 @@ public function getSection(): ?string
* Additional query parameters that won't be prefixed like $arguments (overrule $arguments)
*
* @return array|null
* @deprecated to be removed with Neos 9
*/
public function getAdditionalParams(): ?array
{
return $this->fusionValue('additionalParams');
}

/**
* Query parameters that are appended to the url
*
* @return array|null
*/
public function getQueryParameters(): ?array
{
return $this->fusionValue('queryParameters');
}

/**
* Arguments to be removed from the URI. Only active if addQueryString = true
*
* @return array|null
* @deprecated to be removed with Neos 9
*/
public function getArgumentsToBeExcludedFromQueryString(): ?array
{
Expand All @@ -140,6 +165,7 @@ public function getArgumentsToBeExcludedFromQueryString(): ?array
* If true, the current query parameters will be kept in the URI
*
* @return boolean
* @deprecated to be removed with Neos 9
*/
public function isAddQueryString(): bool
{
Expand Down Expand Up @@ -195,13 +221,20 @@ public function evaluate()
}

try {
return $uriBuilder->uriFor(
$uriString = $uriBuilder->uriFor(
$this->getAction(),
$this->getArguments(),
[... $this->getArguments(), ...$this->getRoutingArguments()],
$this->getController(),
$this->getPackage(),
$this->getSubpackage()
);
$queryParameters = $this->getQueryParameters();
if (empty($queryParameters)) {
return $uriString;
}
$uri = new Uri($uriString);
parse_str($uri->getQuery(), $queryParametersFromRouting);
return (string)$uri->withQuery(http_build_query([...$queryParametersFromRouting, ...$queryParameters]));
} catch (\Exception $exception) {
return $this->runtime->handleRenderingException($this->path, $exception);
}
Expand Down
2 changes: 2 additions & 0 deletions Neos.Fusion/Resources/Private/Fusion/Root.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ prototype(Neos.Fusion:ResourceUri) {
prototype(Neos.Fusion:ActionUri) {
@class = 'Neos\\Fusion\\FusionObjects\\ActionUriImplementation'
request = ${request}
routingArguments = Neos.Fusion:DataStructure
queryParameters = Neos.Fusion:DataStructure
additionalParams = Neos.Fusion:DataStructure
arguments = Neos.Fusion:DataStructure
argumentsToBeExcludedFromQueryString = Neos.Fusion:DataStructure
Expand Down
44 changes: 40 additions & 4 deletions Neos.Neos/Classes/Fusion/NodeUriImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* source code.
*/

use GuzzleHttp\Psr7\Uri;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Log\ThrowableStorageInterface;
use Neos\Flow\Log\Utility\LogEnvironment;
Expand Down Expand Up @@ -86,20 +87,47 @@ public function getSection()
return (string)$this->fusionValue('section');
}

/**
* Controller arguments
*
* @return array
* @deprecated
*/
public function getArguments(): array
{
$arguments = $this->fusionValue('arguments');
return is_array($arguments) ? $arguments : [];
}

/**
* Additional query parameters that won't be prefixed like $arguments (overrule $arguments)
*
* @return array
* @deprecated
*/
public function getAdditionalParams(): array
{
$params = $this->fusionValue('additionalParams');
return is_array($params) ? $params : [];
}

/**
* Additional query parameters that won't be prefixed like $arguments (overrule $arguments)
*
* @return array
* @deprecated To be removed with Neos 9
*/
public function getAdditionalParams()
public function getQueryParameters(): array
{
return array_merge($this->fusionValue('additionalParams'), $this->fusionValue('arguments'));
$params = $this->fusionValue('queryParameters');
return is_array($params) ? $params : [];
}

/**
* Arguments to be removed from the URI. Only active if addQueryString = true
*
* @return array
* @deprecated To be removed with Neos 9
*/
public function getArgumentsToBeExcludedFromQueryString()
{
Expand All @@ -110,6 +138,7 @@ public function getArgumentsToBeExcludedFromQueryString()
* If true, the current query parameters will be kept in the URI
*
* @return boolean
* @deprecated To be removed with Neos 9
*/
public function getAddQueryString()
{
Expand Down Expand Up @@ -154,17 +183,24 @@ public function evaluate()
}

try {
return $this->linkingService->createNodeUri(
$uriString = $this->linkingService->createNodeUri(
$this->runtime->getControllerContext(),
$this->getNode(),
$baseNode,
$this->getFormat(),
$this->isAbsolute(),
$this->getAdditionalParams(),
[...$this->getArguments(), ...$this->getAdditionalParams()],
$this->getSection(),
$this->getAddQueryString(),
$this->getArgumentsToBeExcludedFromQueryString()
);
$queryParameters = $this->getQueryParameters();
if (empty($queryParameters)) {
return $uriString;
}
$uri = new Uri($uriString);
parse_str($uri->getQuery(), $queryParametersFromRouting);
return (string)$uri->withQuery(http_build_query([...$queryParametersFromRouting, ...$queryParameters]));
} catch (NeosException $exception) {
// TODO: Revisit if we actually need to store a stack trace.
$logMessage = $this->throwableStorage->logThrowable($exception);
Expand Down
21 changes: 12 additions & 9 deletions Neos.Neos/Documentation/References/NeosFusionReference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -667,12 +667,14 @@ Built a URI to a controller action
:subpackage: (string) The subpackage, empty by default
:controller: (string) The controller name (e.g. ``'Registration'``)
:action: (string) The action name (e.g. ``'new'``)
:arguments: (array) Arguments to the action by named key
:routingArguments: (array) That are handled by the router
:arguments: (@deprecated, array) Arguments to the action by named key
:format: (string) An optional request format (e.g. ``'html'``)
:section: (string) An optional fragment (hash) for the URI
:additionalParams: (array) Additional URI query parameters by named key
:addQueryString: (boolean) Whether to keep the query parameters of the current URI
:argumentsToBeExcludedFromQueryString: (array) Query parameters to exclude for ``addQueryString``
:additionalParams: (@deprecated, array) Additional URI query parameters by named key
:queryParameters: (array) Query parameters that are appended after routing
:addQueryString: (@deprecated, boolean) Whether to keep the query parameters of the current URI
:argumentsToBeExcludedFromQueryString: (@deprecated, array) Query parameters to exclude for ``addQueryString``
:absolute: (boolean) Whether to create an absolute URI

Example::
Expand All @@ -693,7 +695,7 @@ Link to the content module::
package="Neos.Neos.Ui"
controller="Backend"
action = 'index'
arguments.node = ${documentNode}
routingArguments.node = ${documentNode}
}

Link to backend modules (other than `content`)::
Expand All @@ -703,7 +705,7 @@ Link to backend modules (other than `content`)::
action = "index"
package = "Neos.Neos"
controller = "Backend\\Module"
arguments {
routingArguments {
module = 'administration/sites'
moduleArguments {
@action = 'edit'
Expand Down Expand Up @@ -1409,9 +1411,10 @@ Build a URI to a node. Accepts the same arguments as the node link/uri view help
:node: (string/Node) A node object or a node path (relative or absolute) or empty to resolve the current document node
:format: (string) An optional request format (e.g. ``'html'``)
:section: (string) An optional fragment (hash) for the URI
:additionalParams: (array) Additional URI query parameters.
:argumentsToBeExcludedFromQueryString: (array) Query parameters to exclude for ``addQueryString``
:addQueryString: (boolean) Whether to keep current query parameters, defaults to ``FALSE``
:queryParameters: (array) Query parameters that are appended after routing
:additionalParams: (@deprecated, array) Additional URI query parameters.
:argumentsToBeExcludedFromQueryString: (@deprecated, array) Query parameters to exclude for ``addQueryString``
:addQueryString: (@deprecated, boolean) Whether to keep current query parameters, defaults to ``FALSE``
:absolute: (boolean) Whether to create an absolute URI, defaults to ``FALSE``
:baseNodeName: (string) Base node context variable name (for relative paths), defaults to ``'documentNode'``

Expand Down
3 changes: 3 additions & 0 deletions Neos.Neos/Resources/Private/Fusion/Prototypes/NodeLink.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
prototype(Neos.Neos:NodeLink) < prototype(Neos.Fusion:Tag) {
node = null
queryParameters = Neos.Fusion:DataStructure
additionalParams = Neos.Fusion:DataStructure
arguments = Neos.Fusion:DataStructure
argumentsToBeExcludedFromQueryString = Neos.Fusion:DataStructure
Expand All @@ -13,6 +14,7 @@ prototype(Neos.Neos:NodeLink) < prototype(Neos.Fusion:Tag) {
@context {
node = ${this.node}
additionalParams = ${this.additionalParams}
queryParameters = ${this.queryParameters}
arguments = ${this.arguments}
argumentsToBeExcludedFromQueryString = ${this.argumentsToBeExcludedFromQueryString}
addQueryString = ${this.addQueryString}
Expand All @@ -24,6 +26,7 @@ prototype(Neos.Neos:NodeLink) < prototype(Neos.Fusion:Tag) {
attributes {
href = Neos.Neos:NodeUri {
node = ${node}
queryParameters = Neos.Fusion:DataStructure
additionalParams = ${additionalParams}
arguments = ${arguments}
argumentsToBeExcludedFromQueryString = ${argumentsToBeExcludedFromQueryString}
Expand Down
2 changes: 2 additions & 0 deletions Neos.Neos/Resources/Private/Fusion/Prototypes/NodeUri.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#
prototype(Neos.Neos:NodeUri) {
@class = 'Neos\\Neos\\Fusion\\NodeUriImplementation'
routingArguments = Neos.Fusion:DataStructure
queryParameters = Neos.Fusion:DataStructure
additionalParams = Neos.Fusion:DataStructure
arguments = Neos.Fusion:DataStructure
argumentsToBeExcludedFromQueryString = Neos.Fusion:DataStructure
Expand Down

0 comments on commit a707730

Please sign in to comment.