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

Add request to routing arguments #741

Merged
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion docs/redirect.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ After adding or editing a book, it will be redirected to the edition page of a b

You can pass arguments to your redirection method.

2 variables are available:
3 variables are available:

* `resource`: to retrieve data from the instantiated resource
* `{name_of_your_resource}`: If your resource is a book instance, it will be also available as `book` variable
* `request`: to retrieve data from the request via Symfony\Component\HttpFoundation\Request

It uses the [Symfony expression language](https://symfony.com/doc/current/components/expression_language.html) component.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<argument type="service" id="request_stack" />
<tag name="sylius.resource_factory_variables" />
<tag name="sylius.repository_variables" />
<tag name="sylius.routing_variables" />
</service>

<service id="sylius.expression_language.variables_collection.factory" class="Sylius\Component\Resource\Symfony\ExpressionLanguage\VariablesCollection">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function testResourceFactoryArgumentParser(): void
$this->assertInstanceOf(ArgumentParserInterface::class, $argumentParser);
$this->assertTrue($argumentParser->parseExpression('token.getUser() === null'));
$this->assertTrue($argumentParser->parseExpression('user === null'));
$this->assertTrue($argumentParser->parseExpression('request === null'));
}

public function testRepositoryArgumentParser(): void
Expand All @@ -44,6 +45,7 @@ public function testRepositoryArgumentParser(): void
$this->assertInstanceOf(ArgumentParserInterface::class, $argumentParser);
$this->assertTrue($argumentParser->parseExpression('token.getUser() === null'));
$this->assertTrue($argumentParser->parseExpression('user === null'));
$this->assertTrue($argumentParser->parseExpression('request === null'));
}

public function testRoutingArgumentParser(): void
Expand All @@ -54,6 +56,7 @@ public function testRoutingArgumentParser(): void

/** @var ArgumentParserInterface $argumentParser */
$argumentParser = $container->get('sylius.expression_language.argument_parser.routing');
$this->assertTrue($argumentParser->parseExpression('request === null'));

$this->assertInstanceOf(ArgumentParserInterface::class, $argumentParser);
}
Expand Down
Loading