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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Issue summary: View changes
Berdir’s picture

So an idea I recently mentioned to @plach is that Entity::urlInfo() should automatically respect the current language if not defined explicitly.

$translation = $entity->getTranslation('de');
$translation->urlInfo()

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..?

dawehner’s picture

It 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?

Berdir’s picture

Probably 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.

Berdir’s picture

Status: Active » Needs review
FileSize
724 bytes

Just trying out what happens if we do this :)

dawehner’s picture

Fair. Let's see whether hell freezes.

Status: Needs review » Needs work

The last submitted patch, 5: default-language-2428103-5.patch, failed testing.

jhodgdon’s picture

Not too horrible, only 2 fails! Hell is only slightly frosty.

Berdir’s picture

Status: Needs work » Needs review

Didn'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...

Berdir’s picture

Status: Needs review » Needs work

Didn't mean to set to needs review, although I guess we could use some feedback from @plach/@Gabor.

Gábor Hojtsy’s picture

Issue tags: +D8MI, +language-content, +sprint

I think this makes sense. I am not concerned that it will add a little bit more semantic markup to single language sites too.

Berdir’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests
FileSize
2.42 KB
1.71 KB

Fixing the test fails, this needs tests.

balagan’s picture

I 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.

Berdir’s picture

This 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.

Gábor Hojtsy’s picture

Issue tags: -sprint

Not actually being worked on :/

dawehner’s picture

FileSize
2.39 KB
1.38 KB

Let's try whether its works on EntityBase as well.

Status: Needs review » Needs work

The last submitted patch, 16: 2428103-16.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
6.17 KB
4.36 KB

I'm not really sure about the check for the link relation

Status: Needs review » Needs work

The last submitted patch, 18: 2428103-18.patch, failed testing.

jibran’s picture

+++ b/core/modules/statistics/src/Tests/StatisticsReportsTest.php
@@ -49,7 +49,9 @@ function testPopularContentBlock() {
+    //from being added to the options.

space missing after //.

AjitS’s picture

Assigned: Unassigned » AjitS
Issue tags: +#drupalgoa2015

Working on this now.

AjitS’s picture

Assigned: AjitS » Unassigned
Status: Needs work » Needs review
FileSize
735 bytes
6.17 KB

Changes done as per #20.
I was not sure about the failing tests.

Status: Needs review » Needs work

The last submitted patch, 22: string_formatter_should-2428103-22.patch, failed testing.

The last submitted patch, 22: string_formatter_should-2428103-22.patch, failed testing.

dawehner’s picture

Fixing the tests shouldn't be hard.

dawehner’s picture

Fixing the tests shouldn't be hard.

amateescu’s picture

FileSize
6.62 KB
687 bytes

We 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 :/

dawehner’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests +blocker, +D8 Accelerate
FileSize
3.05 KB
7.54 KB

Fixed the unit test and make it more sane by doing so.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

My 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.

The last submitted patch, 27: 2428103-25.patch, failed testing.

isntall queued 27: 2428103-25.patch for re-testing.

The last submitted patch, 27: 2428103-25.patch, failed testing.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

I 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.

dawehner’s picture

FileSize
12.47 KB
5.75 KB

Fair, 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 .

Status: Needs review » Needs work

The last submitted patch, 34: 2428103-34.patch, failed testing.

catch’s picture

Priority: Normal » Critical
amateescu’s picture

Status: Needs work » Needs review
FileSize
13.45 KB
1.72 KB

This should fix the test fails.

dawehner’s picture

Looks fine, but shouldn't we expand the EntityUrlTest coverage in order to ensure that it actually works?

Status: Needs review » Needs work

The last submitted patch, 37: 2428103-37.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
14.55 KB
1.1 KB

Fixed the failures.

dawehner’s picture

FileSize
19.21 KB
5.08 KB

Expanded the test coverage ...

amateescu’s picture

+++ b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
@@ -110,18 +140,24 @@ public function providerTestUrlInfoForInvalidLinkTemplate() {
+   * @return \Drupal\Core\Url The URL for this entity's link template.
+   * The URL for this entity's link template.

Blaming the storm again :P

dawehner’s picture

FileSize
19.1 KB
816 bytes
amateescu’s picture

Status: Needs review » Reviewed & tested by the community

The test coverage added in #41 looks great.

dawehner’s picture

Issue summary: View changes

Adapted the IS.

webchick’s picture

Priority: Critical » Major

I 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.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.0.x, thanks!

  • catch committed 74db053 on 8.0.x
    Issue #2428103 by dawehner, amateescu, Berdir, AjitS: String formatter...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.