i am newbee in Symfony2.
I'm wondering if it is possible to override default hardcoded locale in parameters.yml and set one i.e from a #service ??
The task is to manage languages and locales from admin area (e.g. added and stored in database). And to use default one, based on this data.
I've tried to use LocaleListener described here http://symfony.com/doc/current/cookbook/session/locale_sticky_session.html
but anyway it takes %default_locale% from parameters for the first request.
Also, there are a lot of nice bundles for route translations as JMSI18nRoutingBundle
and LexikTranslationBundle for translations, but all of them use in configuration hardcoded %default_locale% and/or locale lists.
Is it possible to solve this somehow with Symfony2? Thanks in advance.
Related
Is it possible to use a different class for sonata.media.adapter.filesystem.s3 service? Right now I can see it's hardcoded in gaufrette.php:
->set('sonata.media.adapter.filesystem.s3', AwsS3::class)
->args(['', '', ''])
Is it possible to override this behaviour and set any other adapter class, e.g. Gaufrette\Adapter\AsyncAwsS3?
According to Symfonys architecture it should be possible to override pretty much everything: https://symfony.com/doc/current/bundles/override.html#services-configuration
If you want to modify the services created by a bundle, you can use service decoration. If you want to do more advanced manipulations, like removing services created by other bundles, you must work with service definitions inside a compiler pass.
Most probably you solution is the latter. Here is an existing question on how to do that: Symfony: Overriding Symfony service ( compiler pass )
I have a huge problem that I couldn't resolve in the last few days. I don't expect you to give me a final solution because I think the problem is not so simple.
So I have a huge Symfony2 application that was built with the idea to work only with one language. All routes are in their responsible controllers. Now I want to prefix all routes with the selected language so could have:
myapp.com/en/news
myapp.com/fr/news
etc...
And if it is possible the default language should not be shown in the route - if English is my default language I want only myapp.com/news. The problem is that I can't just go through all routes and make them work both with optional parameter about the language and also work without that parameter. If it is not possible I am ok en to be presented in the route too.
I tried the jmsi18nroutingbundle because many other people suggested it but when I setup the config.yml as it is said only some of the routes get prefix when I check them with app/console debug:router. And because of that I am either not configuring it well or it has some limitations.
My question is how do you handle multilingual websites and their routes - do you start with the idea about multilingual system from the beginning and create at least two routes for each action one with optional parameter about the language and one without that parameter or you have more global solution to handle all routes?
I'm playing with Symfony reusable bundles and I want to make some bundle with default configuration for all my other projects like common entities, controllers etc. But the problem is taht I want to keep some default configuration for 3rd party bundles in that bundle too (easy admin, fos user bundle,...).
I would like to set some default configuration in my bundle and in case of need override it in app/config... Is this possible and if yes, how can I achieve that.
Thanks in advance
You need use prepend extension config for keep other extension configurations.
Follow the documantation
https://symfony.com/doc/current/bundles/prepend_extension.html
You can maybe write a compiler pass that will set parameters in your 3rd party bundle.
Here is an example of compiler pass I did here.
so in your compiler pass you would have something like:
$fosParameters = ['db_driver' => 'orm', 'firewall_name' => 'main'];
$container->setParameter(
'fos_user',
$fosParameters
);
also, do not forget to add your compiler pass to your bundle file like I did here.
I am not 100% sure this will work but I do not see why it would not work.
I have been coding in SYmfony since last 6 months now. And after completing a couple of projects, I started exploring symfony in greater details. While exploring i came accross, TreeBuilder component. Now, i understood the concept TreeBuilder very well. Its basically used to dump config files in YML. But, the question is, why would one use TreeBUilder when you can directly modify the condig yml files.? Is there any other better use case where one should use TreeBUilder specificaly.? Could you please help me understand any use case. This will give me a better understanding.
According to documentation Tree builder is a component which can/should be used to validate configuration provided by end user.
Configuration values are usually expected to show some kind of
hierarchy. Also, values should be of a certain type, be restricted in
number or be one of a given set of values. For example, the following
configuration (in YAML) shows a clear hierarchy and some validation
rules that should be applied to it (like: "the value for auto_connect
must be a boolean value")
So basically you can make a set of requirements to configuration of your bundle like
required
default value
type constraint
For complete reference check documentation
I have to manage a multilingual routing as part of a Symfony2 project.
In order to get the whole URL translated i have to access the EntityManager from the PHP routing file to get the proper translation and the translated slugs.
Does anyone know how to do that ?
Thanking you,
Antoine.
May be you have to make separate third-level domain for each language (ru.site.com, fr.site.com) and generate routes using your database translation table from template?
What I could suggest you is to check the JMSI18nRoutingBundle. This bundle let you define localized routes. Here ta copy of the overview text for the bundle taken from the documentation:
Overview
This bundle allows you to create i18n routes. Key points:
uses the Translation component; translate URLs just like you would translate any other text on your website
allows you to use different hosts per locale
does not require you to change your development processes
can translate all routes whether they are coming from third-party bundles, or your own application
I did not use it myself and I'm not the developer of this bundle and I don't know if it will work for your slug. But I hope this will help you in some ways.
Regards,
Matt