Author of this module comments
simple_favs 2.0.10 was designed to support either unilingual non multlingual sites that have no language prefix
OR
Multilingual sites that have a two letter language prefix. This assumes that when using multilingual that each node gets a language assigned (not language undefined). only unilingual sites are able to use language undefined. If your nodes in a multilingual build have language undefined then they should be assigned to the language default of the site which assuming is not undefined. Howto fix this without patching simple_favs.
A way forward:
I'll consider patches that do not break functionality for existing builds.
NO PATCH NEEDED BY FIXING YOUR CONTENT AND CONFIGURATION:
To fix your language undefined nodes, write a schema update using a hook_update / mymodule_update_10001() , this function call goes into mymodule.install , in this schema update you'll need to set the language to your sites default language instead of language undefined. Then in your node bundle settings set the default language code to the sites default language.
Original reported issue:
I have a site that has content in two languages, English (en) and Irish (ga). The English version is set as the default so the language for those node is often set as undefined (und).
When viewing the favourited items in the "My Favourites" block, the URLs are incorrect and go to invalid routes on the site. This is because the url is created using the following code (js/favsBlock.js:64):
const url = (langcode !== 'und') ? '/' + langcode + '/node/' + id : '/node/' + id;
The langcode is the language that the viewer requested and not that of the node, as far as I can tell. The value comes from drupalSettings.simple_favs.block.langcode.
This results in the generated URL as /en/node/123 and not the expected /node/123.
I see two possibilities to fix this. Either store the correct URL as is done with non-node URLs or return the URL in the call to /simple-favs/titles. I suspect the returning the URL in the JSON would be the preferred solution as that would account for changing the alias of the node.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3561865-botch.patch | 2.17 KB | john cook |
Comments
Comment #2
john cook commentedFor a work-around, I changed the saving function to us the
isInFavsOther()method. I do not recommend using this as it bypasses functionality to store favourites in a more condense manner. But I believe that this would be backwards compatible with the proper fix.Comment #3
joseph.olstadHmmm
Comment #4
joseph.olstadComment #5
joseph.olstadYa this module was designed to support multilingual sites that use a lang prefix like /en/ or /fr/ and sites that have only one language with no prefix.
I'm guessing that your build does not use a language prefix?
To enlarge support for everyone without breaking things will be a big task.
Your initial patch might be onto something however I'll wait until it's fully cooked to test it.
Comment #6
joseph.olstadComment #7
joseph.olstadComment #8
joseph.olstadComment #9
joseph.olstadComment #10
joseph.olstadComment #11
joseph.olstadComment #12
joseph.olstadComment #13
joseph.olstadNo patch needed instructions.
Comment #14
joseph.olstadComment #15
joseph.olstadComment #16
joseph.olstadOk changing this from a bug report to a support request. Since I have documented a way forward which involves correcting your content and adjusting your configuration to ensure this doesn't happen again.
It's possible that a lot of your content was created by script or migration tool and they forgot to set a language code. It's an easy fix to update undefined nodes over to the sites language default language code.
Fix this as described and review your configuration and try again.
Comment #17
joseph.olstadYour translatable fields will likely need to get a language code as well as the node it'self
correct your configuration, create new content correctly and compare with broken content that has language undefined. At this point you'll know what to fix. There's likely an easy way to fix this so look for the easy solution. It's been done before.
The problem is, someone incorrectly created a lot of this content with scripts/migration tools that were half baked.
Comment #18
joseph.olstadactually I think it wound't be that hard to rework this patch so that it doesn't bust multilingual. With that said, I'll wait until someone improves the suggested changes and then I'll have a look again at it. Currently it changes too much logic that affects multilingual support.
What should be done here is to create a new code block for when langcode is 'und' instead of scrapping the logic as we had it. Treat 'und' differently, don't break the rest of our code.
Comment #19
joseph.olstadComment #20
joseph.olstadactually, I could create another patch based on this that would fix the issue and not break multilingual using my suggestion , low effort.
if it's not done in three weeks, ping me and I'll try to find some time to improve this.