Skip to content

[Routing] Allow force-generation of trailing parameters using eg "/exports/news.{!_format}" #29599

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

Merged
merged 1 commit into from
Dec 24, 2018

Conversation

luchaninov
Copy link
Contributor

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #29593
License MIT

When a route is defined as path: /exports/news.{!_format}, we should force _format be defined in defaults and the generator should generate URLs with that default when none is provided (should work with any parameter of course).

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome! just a minor comment and good on my side!

@nicolas-grekas
Copy link
Member

Would you mind creating a doc issue/PR?

$varName = substr($varName, 1);
$coalescing = true;
} else {
$coalescing = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move before if so else can be removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or in one line: if ($important = '!' === $varName[0]) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolas-grekas nice one. To make it more understandable added ( ):
$important = ('!' === $varName[0])

@luchaninov
Copy link
Contributor Author

Would you mind creating a doc issue/PR?

symfony/symfony-docs#10785

Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement 👍🏻

@nicolas-grekas
Copy link
Member

Thank you @luchaninov.

@nicolas-grekas nicolas-grekas merged commit 9fab3d6 into symfony:master Dec 24, 2018
nicolas-grekas added a commit that referenced this pull request Dec 24, 2018
…s using eg "/exports/news.{!_format}" (zavulon)

This PR was squashed before being merged into the 4.3-dev branch (closes #29599).

Discussion
----------

[Routing] Allow force-generation of trailing parameters using eg "/exports/news.{!_format}"

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29593
| License       | MIT

When a route is defined as path: `/exports/news.{!_format}`, we should force `_format` be defined in `defaults` and the generator should generate URLs with that default when none is provided (should work with any parameter of course).

Commits
-------

9fab3d6 [Routing] Allow force-generation of trailing parameters using eg \"/exports/news.{!_format}\"
@Tobion
Copy link
Contributor

Tobion commented Dec 24, 2018

I think the solution with ! is good for forcing the generation of urls with default params. This is already something I tried to tacle before in #5180.
But I suggest to also change the matching for ! prefixed placeholders to not make them optional.
So /news.{!_format} does not match /news. Otherwise we promote duplicate URIs again. If you need /news to also match, you just create a redirect route as explained in #28633 (comment)

javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Jan 2, 2019
This PR was merged into the master branch.

Discussion
----------

[Router] Marking variable as important

symfony/symfony#29599

Commits
-------

34f5dfa [Router] Marking variable as important
@nicolas-grekas
Copy link
Member

See #29763, help wanted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants