For a website I needed a menu that has 3 levels. I created these levels using:
$vars['primary_links_level2'] =i18nmenu_menu_navigation_links('primary-links', 1);
$vars['primary_links_level3'] = i18nmenu_menu_navigation_links('primary-links', 2);
The issue happens when I have a menu item located at level 3 that has for example link_path: foo/bar used in french and dutch. When I select this Item I can only see the active trail in one language. In the other language level 2 and 3 disappear. After debugging some code I found out that the problem is situated here (menu.inc line 898):
$parents = db_fetch_array(db_query("SELECT p1, p2, p3, p4, p5, p6, p7, p8 FROM {menu_links} WHERE menu_name = '%s' AND link_path IN (". $placeholders .")", $args));
It tries to fetch the parents of the current menu item. But if there are 2 menu items (one dutch and one french) with the same link_path. It returns the parents from the first occurring menu item, in this case the dutch one.
Thanks for your help and if you need some more information don't hesitate to contact me.
| Comment | File | Size | Author |
|---|---|---|---|
| #45 | i18n-filter-preferred-link-by-language-881322-45.patch | 4.82 KB | joseph.olstad |
| #43 | i18n-filter-preferred-link-by-language-881322-43.patch | 1008 bytes | stefan.r |
| #43 | interdiff.txt | 1.12 KB | stefan.r |
| #40 | i18n-filter-preferred-link-by-language-881322-40.patch | 817 bytes | smithmilner |
| #31 | i18n-filter-preferred-link-by-language-881322-31.patch | 818 bytes | weri |
Comments
Comment #1
stijnbe commentedComment #2
sven.lauer commentedsubscribe
Comment #3
kompis commentedsubscribe
Comment #4
kompis commentedIf anyone can give some basic outline how I could write a patch and, or where the failure occurs, then I'll have a go - just not sure where to start with this one.
Comment #5
najyk commentedsubscribe
Comment #6
kompis commentedIm planning to work on this tomorrow to try to get a basic patch or override module built. Any pointers in the mean time would be most welcome!
Comment #7
joostvdl commentedThis also is an issue with Drupal 7.
Comment #8
berdirThe attached patch fixes the problem in Drupal 7 by injecting the correct menu link item into the static cache of menu_link_get_preferred(). This is rather hacky because it means that the query will be executed on all sites, not just when requested.
Also, this is only possible in Drupal 7, thanks to drupal_static(). There is no way to solve this problem without hacking core in Drupal 6.
A clean solution would be to request a patch for core that either adds a query alter tag to the query in the function menu_link_get_preferred() or add a drupal_alter() on the returned results.
Comment #9
jose reyero commentedLooks good, though not sure about adding init hooks and more queries for this...
Instead of using menu_init, could we run that function from inside other i18n_menu ones? As I see it, if you don't use i18n_menu_* API to retrieve or alter your menus, multilingual menu items won't work anyway, so...
Maybe we could run it the first time i18n_menu_navigation_links() or i18n_menu_localize_tree() is invoked.
Comment #10
berdirThe problem is that there is no way of knowing if and when menu_link_get_preferred() is called. It is usually rather late but a module might trigger that call earlier.
But we can try to move it to another function, I'l have to check when they are called
As said, the only clean solution would be to open a core issue and request a query tag for that specific query so that we can alter it dynamically.
Comment #11
jose reyero commented@Berdir,
Yes, I understand the issue. My point is that other functions not using i18n_menu api would fail anyway if we have these per language items, so maybe we could fix it in our own API.
And question 2: If we need it as early as possible, why not in hook_boot() ?
> As said, the only clean solution would be to open a core issue and request a query tag for that specific query so that we can alter it dynamically.
Right, I was thinking the same, though feeling too lazy for that :-/
Anyway, as we are doing a 1.0 stable release ASAP (deadline this weekend so it is ready for Drupalcon), feel free to commit this one if this is the best option we've got so far.
(Just add some @todo note and let this issue as open task to work on it later)
Comment #12
kompis commentedThere is a workaround to this issue that I have found that doesn't require patches (tested in D6.22 with i18n 6.19):
Use the 'menu per language' method to create your menus, don't put all your menu items into a single menu.
When you use a single menu per language, nested menu items that have a fixed 'system' path are still shown when you switch language.
While this is a good workaround, it really should work using either method.
Comment #13
jose reyero commentedPatch committed. Thanks.
Comment #15
ludo.rI have created an issue in the core queue for that : http://drupal.org/node/1854134
Comment #16
jose reyero commentedOk, but this one is committed, so reopen if there's any results with the core issue.
Comment #17
EtienneRd commentedThe above solution didn't make it work for me.
In the patch I posted in http://drupal.org/node/1854134, I added a tag in the
menu_link_get_preferred()query.Then I altered the query using hook_query_TAG_alter().
Doing this, menu links are always filtered by the active language.
You can also remove the code of
menu_link_get_preferred()from i18n_menu_init().Comment #19
EtienneRd commentedSorry for the last one.
This one should work.
Comment #21
EtienneRd commentedNow that I finally understood how to submit a patch correctly.
Comment #23
EtienneRd commentedThis patch needs to be used with the one posted here.
It will filter by language menu links, so that if you have two menu items with same link path but different language,
there won't be any collision when determining the active menu trail.
Comment #24
jose reyero commentedSo in any case we should wait for the core patch, I guess.
@Berdir,
As you are following both issues, please feel free to commit this one if you think it makes sense (Hope you don't mind me assigning the issue to you).
Should we rollback the previous one if the core patch gets in? (looks like a cleaner solution, doesn't it?)
@EtienneRd,
For the same link path but different language, wouldn't it be easier just using localizable links?
Also, the previous patch is not working for you?
Comment #25
jose reyero commentedComment #26
harrrrrrr commentedThe patch in #23, combined with the core patch works when you have a single menu in which you put menu items for each language.
Comment #27
czigor commentedThe patch #23 can yield 2 menu links if there is both a LANGUAGE_NONE and a $language->language menu link in the menu_links table. One of them is chosen quite randomly.
I don't know the solution to this. We need a query that selects $language->language if it exists otherwise LANGUAGE_NONE. I think the first result will be selected so an OrderBy that puts LANGUAGE_NONE to the end might do the trick too.
I used the workaround of setting my LANGUAGE_NONE link to a defined language.
Comment #28
jose reyero commentedPostponing until core patch gets in.
Comment #29
xaa commentedhello, any progress on this issue, please ?
Comment #30
weri commentedComment #31
weri commentedI updated the patch #23, because the tag name has changed to 'preferred_menu_links' in patch #11 on issue #1854134-11: Add a query tag to the query in menu_link_get_preferred() to allow modules to alter the query.
Comment #32
akalam commented#31 worked for me in the following circunstances (without any core patch):
- 2 menu links to a taxonomy term
- The menu links has language, and are properly translated (one in catalonian, the other in spanish)
- The vocabulary is configured as "Localize. Termes are common for all languages, but their name and description may be localized."
Note: after applying the patch, I had to clean the cache in order to work
Thanks for the patch, I hope it to be set as RTBC
Comment #33
Photoshopper commented.
Comment #34
antims commented#31 also worked for me.Thanks.
Comment #35
keynone commented#31 works for me as well.
Comment #36
lamp5#31 also worked for me.Thanks.
Please add to dev
Comment #37
pikot commented#31 works for me too. Thanks!
Comment #38
gerson.analista commented#31 works for me too. Thanks!
Please add to dev...
Comment #39
stefan.r commentedunnecessary whitespace
$tables = $query->getTables() should be fine here?
if (Comment #40
smithmilner commentedRerolled #31 with the changes specified in #39.
Comment #41
smithmilner commentedComment #42
daniel korteThis patch works for me. Thanks!
Comment #43
stefan.r commentedMarking RTBC as this only adds some brackets and a comment. Shouldn't we rollback the code from #13 as well?
Comment #44
dandaman commented#43 worked for me. Thanks!
Comment #45
joseph.olstadUsing Stefan.r patch #43 in combination with a rollback of commit from #13 (from 5 years back)
Rolling back code from #13
reroll for test
Comment #46
joseph.olstad#45 is a rollback of this commit:
in combination with patch 43 by @stefan.r
see what the testbot says
Comment #47
joseph.olstadnote: that if we remove i18n_menu_init
then the pending patch in:
#1630706: i18n_menu very slow during install profile due to hook_init() behavior
will not work or will have to be refactored
however,
major performance gains will be achieved by removing i18n_hook_init
see:
#1630706: i18n_menu very slow during install profile due to hook_init() behavior
the performance patch in the above issue will no longer be necessary
HOWEVER, if we combine a refactored patch #43 with patch #1 from
#2447261: Add the 'preferred_menu_links' tag in the i18n_menu_init()
then we'll have best performance and deal with #2447261 at the same time be able to close that.
Comment #49
joseph.olstadComment #51
joseph.olstadComment #52
joseph.olstadok, so scrap #47 ,
#45
or
#43 ?
Comment #53
joseph.olstadComment #54
joseph.olstadah, I see the problem with #47, I'll create a new patch later today or tomorrow.
should be great
Comment #56
joseph.olstadOk, this is fixed in the dev branch, its a bit higher risk change than what was added to the 7.x-1.14 release so lets let this simmer in dev for a while.
The fix as committed using patch #45 knocks off these issues as well:
#2646572: Replace code in hook_init() with hook_query_preferred_menu_links_alter().
AND
resolves this:
#1630706: i18n_menu very slow during install profile due to hook_init() behavior
and possibly also resolves this issue:
#2447261: Add the 'preferred_menu_links' tag in the i18n_menu_init()
Thanks @stefan.r
and everyone else.
Comment #57
joseph.olstadThis fix is in 7.x-1.x dev , if you're happy with this fix in there, I'll tag a new release for this called 7.x-1.15
I'm expecting that @stefan.r suggestion to remove the i18n_menu_init in commit in #55 will improve performance although I haven't yet done any profiling. See
#1630706: i18n_menu very slow during install profile due to hook_init() behavior
I'll be listening for your feedback.
Comment #59
drupalfan2 commentedIs this patch (#43) still necessary for latest Drupal 7 version?
What if the patch is still applied?
Comment #60
joseph.olstadNo patch is necessary for the latest i18n 7.x-1.25
this was fixed and closed a long time back.
If you have some new issue that you think might be related please create a new issue with the explanation and details and you can put a link to it here. All new issues should be new issues, closed fixed issues can get links if they're suspected to be related issues.
If you're having issues with the latest release please open a new support request issue with the explanation and we can investigate .
As a best practice, you should always make a backup of your database before upgrading and you should also try upgrades in a test environment first before upgrading on a production system.