Jump to:
| Project: | Drupal core |
| Version: | 8.x-dev |
| Component: | javascript |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
| Issue tags: | API clean-up, Context, DrupalWTF, JavaScript |
Issue Summary
admin_menu 3.x uses an AJAX/AHAH callback to fetch the menu from the server. Now, I'm about to commit yet another patch to admin_menu to fix an annoying problem of wrong URLs in JavaScript callbacks.
The point is: Whenever you retrieve raw data, such as perhaps a user list for autocompletion, then you do not run into this problem. But whenever you try to retrieve data/content that
a) may be translated or localized
b) may be access-restricted (like node access, e.g. Domain Access)
then Drupal.settings.basePath does not work out at all, because it does not account for any language (path prefix or domain) or any absolute domain/multi-site/section URL components.
I'm running out of ideas, and we badly need to fix this.
function admin_menu_init() {
...
// The base path to use for cache requests depends on whether clean URLs
// are enabled, whether Drupal runs in a sub-directory, and on the language
// system configuration. url() already provides us the proper path and also
// invokes potentially existing custom_url_rewrite() functions, which may
// add further required components to the URL to provide context. Due to
// those components, and since url('') returns only base_path() when clean
// URLs are disabled, we need to use a replacement token as path. Yuck.
$settings['basePath'] = url('admin_menu');...
Drupal.admin.getCache = function (hash, onSuccess) {
...
url: Drupal.settings.admin_menu.basePath.replace(/admin_menu/, 'js/admin_menu/cache/' + hash),Problem: There are countless of things that affect the proper base path for AJAX/AHAH requests.
- Depending on Clean URLs, you need to use
/?q=fooor/foo. (to be continued below) - Depending on the base path, you need to use
/ormy/drupal/. - Depending on the language system configuration, you need to use
/fooor/de/foo. Depending on the language negotiation configuration, the path prefix decides, in which language any content is (or should be) returned. - Depending on any custom_url_rewrite() and custom_url_rewrite_outbound() functions, you possibly need to use
/foo?custom=query. Such additional URL components may be used by modules to provide further context, which in turn, may or may not be used to grant more or less privileges to the current user. (also node_access related) - When Clean URLs are disabled,
url('')returns/(front page), i.e. no?q=at all. - When Clean URLs are enabled,
url('')returns a trailing slash, buturl('foo')returns no trailing slash.
Site note: Drupal.settings.basePath does not account for anything in this list. Which is probably OK for all callbacks that return raw data only (i.e. no content).
Comments
#1
Cross-referencing latest related issue: #469716: Issue when using custom_url_rewrite
#2
Modules like http://drupal.org/project/purl add a whole bunch of further conditions.
#3
And this is a bug, since the new AJAX framework is supposed to return a lot more content via JS.
#4
Tagging.
#5
Tagging absolutely critical clean-ups for D7. Do not touch this tag. Please either help with this or one of the other patches having this tag.
#6
Brainstorming... could this be solved by introducing a Drupal.url() function?
#7
subscribing
#8
#9
#10
Downgrading all D8 criticals to major per http://drupal.org/node/45111
#11
Bugs cannot target D8, as the tree is not open yet.
#12
As far as I understand fixing this issue would also (at least partially) solve the following issues:
#14
We need to live with ugly workarounds in D7. This problem space is too complex to be attacked for D7.
#15
subbing
#16
Subscribe
#17
I personally always do what you suggested in the original issue. I never use Drupal.settings.basePath and always pass callback URLs to the drupal_add_js() manually for all URLs. This way all of Drupal's functionality around URLs (rewrite inbound/outbound, aliases, clean URLs encoding, etc.) all gets taken care of for me. Drupal.settings.basePath is supposed to be there as a convenience, but honestly most of the time it's better to make your own variable when needed for callback URLs used in JavaScript.
This is a request for extending this convenience beyond what it's capable of offering, I don't think the current approaches are "hacks", IMO it's the right way to create URLs on the PHP side and give JavaScript the whole URL. Trying to create full URLs around Drupal.settings.basePath is the wrong approach.
#18
This is a problem for views too. There were issues with custom url parameters, overlay and Ajax submit because there is now way to know which module own which part of the URL.
Any new ideas since last year?