Adding a custom stylesheet on all pages is a bit cumbersome : you have to copy paste an excerpt of the output of app/console config:dump-reference SonataAdminBundle into your config.yml. It would be nice to have an extra_stylesheets and an extra_javascripts option that, when used, would add to the default stylesheets / javascripts instead of replacing them. What do you think ?
I don't understand what you mean. Would you like to add JS/CSS by configuration? Because you can set another template by config extending the default and in css/js blocks call the twig method parent()
@cassianotartari : I'm aware I could do that. Are you aware that you can already add js / css by configuration ? Have a look at app/console config:dump-reference SonataAdminBundle, you'll see what I mean.
Got your point! Yeah, that will be nice! For me would be perfect add some css/js in some edit action, most of time I need to add some specific css/js to some admin form and I need to call configure() extend edit.html.twig and add my scripts. If have some method to add directly by admin class would be perfect. Just don't know about the "MVC" structure...
@cassianotartari : actually, this configuration is used for general scripts, not specific ones. You'll still be forced to extend edit.html.twig if you want to add something to one admin form only. But if you want to tweak something globally, then this new feature would be useful.
Try extending the configuration, by adding extra css/js to the config.yml like this:
sonata_admin:
# ...
assets:
javascripts: # changed order of js assets loading
- 'bundles/sonataadmin/vendor/jquery/dist/jquery.min.js'
- 'bundles/sonataadmin/vendor/jqueryui/ui/minified/jquery-ui.min.js'
- 'bundles/sonataadmin/vendor/jquery.scrollTo/jquery.scrollTo.min.js'
- 'bundles/sonatacore/vendor/moment/min/moment.min.js'
- 'bundles/sonataadmin/vendor/bootstrap/dist/js/bootstrap.min.js'
- 'bundles/sonatacore/vendor/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js'
- 'bundles/sonataadmin/vendor/jqueryui/ui/minified/i18n/jquery-ui-i18n.min.js'
- 'bundles/sonataadmin/jquery/jquery.form.js'
- 'bundles/sonataadmin/jquery/jquery.confirmExit.js'
- 'bundles/sonataadmin/vendor/x-editable/dist/bootstrap3-editable/js/bootstrap-editable.min.js'
- 'bundles/sonataadmin/vendor/select2/select2.min.js'
- 'bundles/sonataadmin/App.js'
- 'bundles/sonataadmin/Admin.js'
It's not perfect, because you have to add the default assets first, and than add your own ones, but it's still better than extend all views you want to add new assets to.
@balazscsaba2006 : you are very nice, but I already tried that too. It works perfectly, but I think we can all agree it is still a workaround. This issue requests a more elegant solution.
:+1:
Maybe there is an optional placeholder that can be used to include the parent assets e.g. in twig:
{% block javascripts %}
{{ parent() }}
{% endblock %}
for the config something like (but with valid YAML):
sonata_admin:
assets:
javascripts:
~
- /bundles/sonatacore/vendor/moment/locale/de.js
:+1:
+1
:+1:
i referenced a PR, maybe someone can review this.
if you guys like, we can change the config name from custom_* to extra_* or anything else!
Oskar
Great job! I indeed would like you to rename the config name to extra_*, it conveys the meaning that the other stylesheets / javascripts will be preserved, while custom_* does not.
@greg0ire i changed it.
further discussion please in the PR itself.
thank you!
:+1: I like the 'extra_*' way
Are there any news about it?
I don't know. @OskarStark , @jvasseur how about reopening #3296 or #3336 ?
My version was a bit hacky but if you want i could rebase it on the last master. This is still a feature that i think is needed. A workaround (that i use) is to keep the config to its default value and add the other assets by extending the sonata layout.
Maybe you could even reopen it on the latest 3.x? Or was there a BC-break?
No, there wasn't any BC break.
Then you should rebase it on 3.x, you will see your changes sooner ;)
:+1:
I don't know. @OskarStark , @jvasseur how about reopening #3296 or #3336 ?
Yes, why not?
Is this still advancing? Would be a great feature
Well, any news on this? Could we go for https://github.com/sonata-project/SonataAdminBundle/pull/3296?
Wouldn't it be better if this is a symfony feature? Appending something to a default config array could be used somewhere else.
Perhaps but by the time it's implemented, we'll be old… plus if we're going to be BC, we're not going to be able to use it for a while.
If someone was to take #3296 and make a new pull request from it on 3.x would it have a chance to get merged or just be a useless duplicate ?
I think that someone would have to look at https://github.com/sonata-project/SonataAdminBundle/issues/4292 first to see if there isn't a more native way to achieve this ;)
I would like this feature
Feel free to work on this @BrianWalters
I took a shot at this @core23! My PR is #4836.
Most helpful comment
:+1:
Maybe there is an optional placeholder that can be used to include the parent assets e.g. in twig:
for the config something like (but with valid YAML):