Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This came up in a discussion with @xjm.
The extent and behavior of JSON:API WRT to multilingual support is not documented and may cause unexpected outcomes.
We should document these facts in the module as a precursor to #2794431: [META] Formalize translations support.
- Status report
- Upon installation
Comment | File | Size | Author |
---|---|---|---|
#34 | interdiff.txt | 506 bytes | Wim Leers |
#24 | 3037804-24.patch | 4.07 KB | Wim Leers |
| |||
#24 | Screenshot 2019-03-06 at 23.26.05.png | 159.56 KB | Wim Leers |
#20 | 3037804-20.patch | 3.27 KB | gabesullice |
| |||
#20 | interdiff.txt | 885 bytes | gabesullice |
Comments
Comment #2
gabesulliceComment #4
Wim LeersCS fix.
Comment #6
Wim LeersNit:
, because we also wrote . Fixed.These changes look 👍 I think we can port these 1:1 to
rest.module
. Do you agree, @xjm?Comment #7
xjmThanks for this! Two small points of feedback:
Let's call the machine key
jsonapi_multilingual_support
. I think we've had bugs before with too-generic requirements keys overwriting each other.We should probably explicitly specify the severity as I always forget what the default is.
Which leads me to the question of whether this should be info or warning, or maybe info at runtime but warning at install time. We have to be careful with warnings at runtime especially if they're something the site owner can't meaningfully address. OTOH the possibility of "unexpected results" for update operations or language negotiation changes does seem to rise to something that we should warn people about.
Thoughts?
Comment #8
xjmI pinged @gaborhojtsy and @plach for feedback on this as well.
Comment #9
Wim LeersComment #10
xjmThanks for the screenshot; that's helpful. It makes me notice that the title and description are redundant. (We've had UX issues about such before; I'd just forgotten.) Maybe the short description should be something like "Limited"? Or, borrowing from https://www.drupal.org/docs/8/modules/jsonapi/translations --something along the lines of "Simple functionality only"?
Comment #11
xjmThat's a weird key structure with both spaces and underscores. Is that intentional, with the
git
in there as well?Most of the
hook_requirements()
keys I've seen are underscore-delimited although it might work with spaces too for all I know.Comment #12
xjmOK, turns out
info
does nothing at install phase, which I also often forget. So we should maybe make it a warning at install time.Comment #13
Wim Leers#10: ✅ Agreed.
#11: ✅LOL that's the wrong window having focus and me having started to type a git command in there. I guess that happens around 1 AM 😅
#12: ✅
Comment #14
Wim LeersI wanted to add updated screenshots for #10, but especially for #12. Apparently
REQUIREMENT_WARNING
only has an effect when installing Drupal (or a Drupal distribution) from scratch, it doesn't trigger a visible warning at all, or a confirm form. I was under the impression that this is what you were expecting/wanting.I just stepped through the module installation code with a debugger to figure it out: the module installation process calls
drupal_check_module()
, which does:As you can see, it only generates a message for
REQUIREMENT_ERROR
.Comment #15
Wim LeersAlso created a sibling issue for
rest.module
: #3037912: Document the extent of REST's multilingual support.. Marked it postponed on this issue, because once we have something we agree on here, we can just port that 1:1.Comment #16
Wim LeersComment #18
Wim LeersTestbot's PHPCS is drunk:
It's telling me to remove leading spaces that need to be there 🙃I'll just put it all on one line then.
Comment #19
Wim LeersTwo nits from a self-review:
Should use strict check.
Should be wrapped in
t()
.Comment #20
gabesulliceUPDATE: Ignore these patches. They were wrong. I RTBC'd #19.
LGTM!
Shall we wait for a +1 from @xjm, or just commit and fix if there's something we missed.
Comment #21
xjmHey thanks! Still waiting from feedback from @gaborhojtsy or @plach as maintainers for the affected features, to make sure this approach is okay given that it affects REST as well as JSON:API.
Comment #22
xjmHere's the updated status report warning. I confirmed it only appears when a multilingual module is also enabled.
I still can't get any message to show up when I install JSON:API either first or second. How do other modules do this? Is it only at Drupal install time rather than module install time or is something broken?
content_translation
is using the messenger service incontent_translation_install()
to post a warning message.media_requirements()
has a bunch of logic in install phase to prevent incompatible modules from being installed, but they are straight up errors.The hook_requirements() documentation documents this:
So, I guess it has to be a DSM. It's easy to add that in
hook_install()
for when JSON:API is installed after the modules, but what about the case where JSON:API is installed first?Comment #23
xjmFWIW @plach gave this issue a 👍and @Gábor Hojtsy said he thinks it's fine, so I think we can go ahead once the above are addressed.
Comment #24
Wim LeersI don't think it ever worked in the way you thought — see #14. I knew you would ask about it, so I already researched it.
DSM won't work when installed using
drush
orcomposer
AFAIK? Anyway, done. It looks like this:🤷♂️ No idea. I don't think that needs to block this though? The status report still informs them.
Comment #25
xjmOops, sorry, missed #14.
Comment #26
xjmRegarding the
hook_install()
for the other modules, I think it's important in both cases, regardless of which you turn on first. I think we have a way in core to react to other modules being enabled; I just can't remember what it is. I'll ask.Comment #27
xjmAh, what we need is hook_modules_installed().
Comment #28
xjmOh RE: DSMs and drush, yeah, we run into this all the time. =/ Ideally we would have some sort of confirm form but I guess modules use
hook_install()
and friends for that instead ofhook_requirements()
(even though it seems like somethinghook_requirements()
should do). But for now the DSM is a good first step.Comment #29
Wim Leers#27: 👍OF COURSE! 😀 I completely forgot that even existed!
Comment #30
Wim LeersIS updated with screenshot for the
case!Comment #31
xjmWe can simplify the code and get rid of the install phase, since we know now it does nothing.
Looks great other than that!
Comment #32
weynhamzThings get really messed up with current multi-lang handling of JSON:API.
I have a multi-lang site with en as default/primary lang, zh-hant as translation.
With below query
I am expecting an empty data array in response, becuase by implicit language neogotiation, the result should be list only en nodes, but as I am filtering with zh-hant and want translation nodes, so there should be none given.
But it gives me tons of nodes which the langcode is en and default_langcode is true, why?
Then, I think by the current logic, it make sense.
The filtering translate to sql query with results of all nodes that have translations, then the lang neogotiation kicks in, returns all these nodes in their eng state.
And this is really confusing.
Comment #34
Wim LeersIt has no effect, but it does get executed during installation.
drupal_check_module()
just chooses to not act on it. That might change in the future (hopefully it will). But: WFM :) Fixed on commit.Comment #35
Wim Leers#32: can you please create a new issue for that? Thanks! 🙏
P.S.: That sounds like an Entity Query bug, I saw a similar support request in the GraphQL Slack channel a week or two ago.
Comment #36
xjmThis line still has the dead half of the ternary:
+ 'severity' => ($phase === 'runtime') ? REQUIREMENT_INFO : REQUIREMENT_WARNING,
Comment #38
Wim Leers#36: fixed in #37.