Problem/Motivation

arg(0) returns 'fr' when two languages are enabled and Language Path Negotiation is enabled and then visiting 'fr/front'. It should return 'front'.
This confuses quite some modules, like the classes for html have the language prefix in, theme suggestions also contain the language prefix.

Proposed resolution

During LanguageNegotiationUrl::getLangcode we know the path prefix and then we can remove it

Remaining tasks

Review

User interface changes

-

API changes

-

Comments

schnitzel’s picture

Issue summary: View changes
schnitzel’s picture

Status: Active » Needs review
StatusFileSize
new3.7 KB
new4.46 KB
dawehner’s picture

The actual bug is that code is using arg() but yeah things aren't simple ... see https://drupal.org/node/788900
arg() should maybe just switch to \Drupal::request()->attributes->get('system_path');

Status: Needs review » Needs work

The last submitted patch, 2: 2251061-arg0-returns-path-prefix-2.patch, failed testing.

schnitzel’s picture

StatusFileSize
new4.46 KB
new3.7 KB
schnitzel’s picture

Status: Needs work » Needs review
tetranz’s picture

I changed the file header to say Contains \Fully\Qualified\Namespace\And\NameOfTheClass instead of Definition of as per https://drupal.org/node/1354#file

Practicing my first patch :)

Status: Needs review » Needs work
tetranz’s picture

I should have made the interdiff a .txt file. I will resubmit after the test completes.

tetranz’s picture

Same as above but interdiff.txt

File header changed to say Contains \Fully\Qualified\Namespace\And\NameOfTheClass instead of Definition of as per https://drupal.org/node/1354#file

yesct’s picture

Issue tags: +D8MI
penyaskito’s picture

Issue tags: +sprint
gábor hojtsy’s picture

Status: Needs review » Needs work
Issue tags: +language-base

Looks like the last test only patch does not fail? Hum.

marthinal’s picture

Status: Needs work » Needs review
Issue tags: +DrupalCampSpain
StatusFileSize
new928 bytes
new3.65 KB

Looks the test is not applied as expected, let's take a look at this. Here a couple of changes.

Status: Needs review » Needs work

The last submitted patch, 14: 2251061-14-only-test.patch, failed testing.

marthinal’s picture

Status: Needs work » Needs review
StatusFileSize
new3.65 KB
new4.41 KB

Let's try again.

schnitzel’s picture

oh thanks @marthinal, looks like the test was never run :)

btw, during working more on our site, I figured out that in some cases LanguageNegotiationUrl::getLangcode() can be called twice, like when a Module want's to load the current langcode. Which as far as I know should not happen, the langcode should be loaded via the request object, but anyway it happens :)
So if this happens there is too much removed from the current path.

This fixes this:

            // Remove the language prefix from _current_path().
            if (strpos(_current_path(), $prefix . '/') === 0) {
              _current_path(substr(_current_path(), strlen($prefix . '/')));
            }

I can change the patch, but I guess you will be faster in it :)

marthinal’s picture

StatusFileSize
new4.5 KB

@Schnitzel sure! done. Many thanks!

The last submitted patch, 16: 2251061-15-only-test-should-fail.patch, failed testing.

schnitzel’s picture

@marthinal
Great, maybe we wanna update the tests as well, that we call LanguageNegotiationUrl::getLangcode() twice, then we also have tested that :)

yesct’s picture

Here's a diff of 15 and 17

< +            _current_path(substr(_current_path(), strlen($prefix) + 1));
---
> +            if (strpos(_current_path(), $prefix . '/') === 0) {
> +              _current_path(substr(_current_path(), strlen($prefix . '/')));
> +            }
marthinal’s picture

18: 2251061-17.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 18: 2251061-17.patch, failed testing.

marthinal’s picture

Status: Needs work » Needs review

18: 2251061-17.patch queued for re-testing.

gábor hojtsy’s picture

#788900: Deprecate and remove usages of arg() (change notice at https://drupal.org/node/2274705) says arg() is deprecated. For the practicalities of this issue, _current_path() is already broken (which is suggested in place of arg() for taking path segments). So this may need to be repurposed to talk about _current_path().

marthinal’s picture

About _current_path().

@todo This is a temporary function pending refactoring Drupal to use Symfony's Request object exclusively.

So, I'm not sure if we should continue working on this using that function.

tstoeckler’s picture

Status: Needs review » Needs work

I think this patch needs to be updated per #2294093: Remove arg(). Or am I missing something?

gábor hojtsy’s picture

Status: Needs work » Closed (works as designed)
Issue tags: -sprint

This looks to be obsolete to me? As explained in the change notice for #2294093: Remove arg() (https://www.drupal.org/node/2274705), you would use route matching. If you have a raw path somehow early in the request and need to match the route, you can use a PathProcessor to remove unwanted things. #1833010: Admin user language preference WSOD if ahead of path prefixes has a solution that now the admin language preference uses to do the same thing before the path itself is processed later on in the request, which you can use to process your path. That will remove any language prefix, resolve aliases, and any other path mangling the negotiators may have done.