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.
Problem/Motivation
If you mark a field to be linked to its entity, the URL should be prefixed with the langcode of the translation.
Proposed resolution
Add 'language' to the URL operations, which then will be used by the language path system, to do its proper job.
Remaining tasks
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#43 | interdiff.txt | 816 bytes | dawehner |
#43 | 2428103-43.patch | 19.1 KB | dawehner |
#41 | interdiff.txt | 5.08 KB | dawehner |
#41 | 2428103-41.patch | 19.21 KB | dawehner |
#40 | interdiff.txt | 1.1 KB | dawehner |
Comments
Comment #1
dawehnerComment #2
BerdirSo an idea I recently mentioned to @plach is that Entity::urlInfo() should automatically respect the current language if not defined explicitly.
So this would automatically add the right language to the urlInfo options unless it is already set.
i think that would be quite intuitive and should fix this and possibly other issues automatically..?
Comment #3
dawehnerIt would be great, indeed. So in case we have a translation add the langcode, otherwise, so if we access the default langcode, don't add it?
Comment #4
BerdirProbably even then.
If you're on /fr, and are displaying content, then some of that content might originally french, so the active language is default, but it might also be originally german and translated. Which is what $this->language() gives you anyway, I think. The only case where I'd not add it is if it is undefined or so.
Comment #5
BerdirJust trying out what happens if we do this :)
Comment #6
dawehnerFair. Let's see whether hell freezes.
Comment #8
jhodgdonNot too horrible, only 2 fails! Hell is only slightly frosty.
Comment #9
BerdirDidn't check the other test yet, but this has an interesting... side effect. Explicitly passing along the language to the url for a link automatically adds hreflang:
<a href="/node/1" hreflang="en">lV81hgzZ</a>
. That makes it fail in the statistics test.Which is not what is generated, because statistics uses that super weird node_title_list() function (it accepts a StatementInterface, WTF, @chx is going to like this :p).
Anyway, I'm wondering if we really want this behavior, because this is now also added on single-language sites, in probably a lot of places, surprised to not see more test fails. I gues most code is consistent in what it uses...
Comment #10
BerdirDidn't mean to set to needs review, although I guess we could use some feedback from @plach/@Gabor.
Comment #11
Gábor HojtsyI think this makes sense. I am not concerned that it will add a little bit more semantic markup to single language sites too.
Comment #12
BerdirFixing the test fails, this needs tests.
Comment #13
balagan CreditAttribution: balagan commentedI was trying to review, but I am not sure if I understand the problem correctly. If I create a view with a page that shows the articles, they both link to the same (English) article without a language prefix. I think berdir's code in the patch in comment #12 does not run when opening the page of the view, I have put an exit() befor the return, and the page is properly displayed. Maybe it is the wanted behaviour, I am not sure.
Comment #14
BerdirThis will probably only be relevant for views in combination with #2342045: Standard views base fields need to use same rendering as Field UI fields, for formatting, access checking, and translation consistency. it also depends on how you print the link there, but for example he Node views field plugin uses Url::fromRoute('entity.node.canonical', ['node' => $this->getValue($values, 'nid')]) instead of $values->_entity->urlInfo(). If you update it like that, then it should work, but the referenced issue will probably remove that plugin anyway.
Comment #15
Gábor HojtsyNot actually being worked on :/
Comment #16
dawehnerLet's try whether its works on EntityBase as well.
Comment #18
dawehnerI'm not really sure about the check for the link relation
Comment #20
jibranspace missing after //.
Comment #21
AjitSWorking on this now.
Comment #22
AjitSChanges done as per #20.
I was not sure about the failing tests.
Comment #25
dawehnerFixing the tests shouldn't be hard.
Comment #26
dawehnerFixing the tests shouldn't be hard.
Comment #27
amateescu CreditAttribution: amateescu for Drupal Association commentedWe also need to pass $options to the Url class, fixed that in this patch. I also tried to look at the test failures but I have no idea how to debug phpunit so I had to give up :/
Comment #28
dawehnerFixed the unit test and make it more sane by doing so.
Comment #29
amateescu CreditAttribution: amateescu for Drupal Association commentedMy contribution here was minimal and I reviewed the code a couple of times already, I think this is ready.
Note that the 'blocker' tag added above is for #2473989: Lack of dynamic language field / filter makes shipping core views hard to be both compatible with mono and multilingual and #2476563: Entity operations links tied to original entity language, ignore everything else, which are critical.
Comment #33
alexpottI might be missing something but I can't see where a test of a url with a language has been added? Or is the unit test enough? This seems like something that would benefit from an integration test.
Comment #34
dawehnerFair, working on some integration test.
Fair, its absolute non trivial to setup the language system correctly,
though it turned out, we never had properly working code .
Comment #36
catchApparently this blocks #2476563: Entity operations links tied to original entity language, ignore everything else so bumping priority.
Comment #37
amateescu CreditAttribution: amateescu for Drupal Association commentedThis should fix the test fails.
Comment #38
dawehnerLooks fine, but shouldn't we expand the EntityUrlTest coverage in order to ensure that it actually works?
Comment #40
dawehnerFixed the failures.
Comment #41
dawehnerExpanded the test coverage ...
Comment #42
amateescu CreditAttribution: amateescu for Drupal Association commentedBlaming the storm again :P
Comment #43
dawehnerComment #44
amateescu CreditAttribution: amateescu for Drupal Association commentedThe test coverage added in #41 looks great.
Comment #45
dawehnerAdapted the IS.
Comment #46
webchickI tried to take a look at this, but it's a bit over my head for the amount of time I have left today. :(
So for now, just downgrading, per #2473989-51: Lack of dynamic language field / filter makes shipping core views hard to be both compatible with mono and multilingual. This is no longer in the critical path once #2485159: Switch admin/content from showing one translation per row to one node per row is fixed.
Comment #47
catchCommitted/pushed to 8.0.x, thanks!