Problem/Motivation

On a multilingual site like Demo Umami, I want to display the link URL in the Cookie banner for Cookie documentation, Privacy policy, Imprint, in the same language as the one being displayed.

In the case of Demo Umami, when I click on the cookie documentation link in the Cookie banner on the Spanish page, I will be redirected to the English page, which is the default language of the site.

If I set the link destination of the cookie documentation to /node/[nid], the link destination will be a URL in the same language as the one being displayed.
However, I would like to display URLs defined in the module's routing.yml and Path alias URLs in the same way.

CommentFileSizeAuthor
#6 3249606-6.patch793 bytesgresko8
#5 3249606-5.patch776 byteskazuko.murata

Issue fork cookies-3249606

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

kazuko.murata created an issue. See original summary.

anybody’s picture

Category: Support request » Feature request
Priority: Normal » Minor
Status: Active » Postponed (maintainer needs more info)

@kazuko.murata thank you.

If I set the link destination of the cookie documentation to /node/[nid], the link destination will be a URL in the same language as the one being displayed.

Do I get you right, if you use /node/[nid] then the link is correctly delivered in the expected languages?

Please try to create Drupal custom menu items for the requests here:

However, I would like to display URLs defined in the module's routing.yml and Path alias URLs in the same way.

What are the results for menu items? How does Drupal handle this? I guess that's a good reference we should use in COOKiES.

kazuko.murata’s picture

@Anybody thank you.

Do I get you right, if you use /node/[nid] then the link is correctly delivered in the expected languages?

Yes. If I use /node/[nid], I can be taken to the page in the expected language.
For example, if the default language of the site is English, and I register /node/6 in the Privacy uri, the link will be displayed as /node/6 on English pages, and /es/node/6 on Spanish pages.

What are the results for menu items? How does Drupal handle this?

The menu item can go to the page in the expected language.
The link of the menu item seems to be controlled by the link field type (core/modules/link/src/Plugin/Field/FieldType/LinkItem.php).

anybody’s picture

@kazuko.murata Tanks? So are menu and COOKiES behaving equally or different?

kazuko.murata’s picture

StatusFileSize
new776 bytes

@Anybody

The behavior of menu and COOKiES is different.

The most minimal fix is
I suppose that this issue can be solved by adding a process like the attached patch.

Could you please check this?

gresko8’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new793 bytes

The problem is that cookie banner links are only pointing to the correct language version if they are node urls. The patch in comment #5 did not work for me. I have created a patch that rewrites all paths and serves the correct language version.

anybody’s picture

Status: Needs review » Needs work

Just an idea: Couldn't we use the same logic as custom menu items or link fields for example? They are well tested...

Perhaps something like this:

Url::fromUri('internal:' . $config[$uri])->toString();

If we want to ensure it's always an internal path starting with / we could add something like this to the validation:

    if (($value = $form_state->getValue('XXXX')) && $value[0] !== '/') {
      $form_state->setErrorByName('XXXX', $this->t("The path '%path' has to start with a slash.", ['%path' => $form_state->getValue('action_url')]));
    }

I think @JFeltkamp should add his two cent what we'd like to support in that field. For me relative URLs would be totally fine, but link field for example also has code to allow external URLs if we really want that!

anybody’s picture

anybody’s picture

Version: 1.0.x-dev » 1.1.x-dev
kaszarobert’s picture

We have a multilanguage site where we use a URL prefix such as /en/article1 or /de/article1. The cookie documentation page by default does not put these language prefixes in this case. This means if someone opens /de/article1 and opens the cookie banner with #editCookieSettings and clicks to the documentation link /cookies/documentation, the visitor will be redirected to the default English language version, in our case to /en/cookies/documentation even though he visited a German page.

With patch #6 now everything works fine. Even on the latest 2.0.0-alpha5.

anybody’s picture

Please use a MR instead of patches, thank you!