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

Inform about JMSI18nRoutingBundle compatibility #352

Merged
merged 1 commit into from Aug 10, 2019

Conversation

benjamintoussaint
Copy link
Contributor

I've spent the last day trying to figure out why routes could not be dumped anymore to JS in my app.
I'm hoping to save hours of trouble for other developers who would encounter the exact same issue.

exposed domain feature introduced in FOSJsRoutingBundle 2.3.0 unfortunately prevents dumping JMSI18nRoutingBundle internationalized routes.

The exposed routes defined in app/config/config.yml are now transformed into a regular expression:

(?P<default>route_1|route_2)

The problem when using JMSI18nRoutingBundle is that the names of the routes are locale-prefixed, so that in the loop through all routes:

foreach ($collection->all() as $name => $route) {

The variable $name would not be route_1 or route_2, such as defined in app/config/config.yml, but rather en__RG__route_1 or en__RG__route_2.

So when populating the $matches array using the original routes names and then attempting to get their corresponding domain using the locale-prefixed routes names, well, that returns null and continues the loop:

preg_match('#' . $this->pattern . '#', $name, $matches);

if (count($matches) === 0) {
    continue;
}

$domain = $this->getDomainByRouteMatches($matches, $name);

if (is_null($domain)) {
    continue;
}

After some thoughts, I've stumbled upon a very easy solution consisting in adapting the routes defined in app/config/config.yml so that they would be used as locale-prefixed in the loop!

Tada :)

I hope that it's the right place to inform about this issue, please let me know otherwise, thank you.

FOSJsRoutingBundle 2.3.0 introduced domain feature that prevents dumping JMSI18nRoutingBundle routes
@benjamintoussaint
Copy link
Contributor Author

Please let me know if you need more information 🤓

@tobias-93 tobias-93 merged commit 6220f4f into FriendsOfSymfony:master Aug 10, 2019
@tobias-93
Copy link
Collaborator

Thanks @benjamintoussaint, this combines great with #334

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

Successfully merging this pull request may close these issues.

None yet

2 participants