Problem/Motivation

If the frontpage "url" is passed through \Drupal\graphql_core_schema\Plugin\GraphQL\DataProducer\LanguageSwitchLinks::resolve() the resolved language switcher links point to the entity / path instead the frontpage.

The tests have been written using LLM support - the rest by a grumpy organic developer :)

Steps to reproduce

A query like:

query Routing {
  route(path: "/", skipFrontpageRedirect: true) {
    ... on InternalUrl {
      languageSwitchLinks {
        url {
          path
        }
        title
      }
    }
  }
}

Returns

{
  "data": {
    "route": {
      "languageSwitchLinks": [
        {
          "url": {
            "path": "/en/my-homepage"
          },
          "title": "English"
        },
        {
          "url": {
            "path": "/de/meine-homepage"
          },
          "title": "German"
        },
      ]
    }
  }
}

Instead of

{
  "data": {
    "route": {
      "languageSwitchLinks": [
        {
          "url": {
            "path": "/en"
          },
          "title": "English"
        },
        {
          "url": {
            "path": "/de"
          },
          "title": "German"
        },
      ]
    }
  }
}

Proposed resolution

Add a similar approach in \Drupal\graphql_core_schema\Plugin\GraphQL\DataProducer\LanguageSwitchLinks::resolve() as \Drupal\language\Plugin\Block\LanguageBlock::build() uses and use the <front> placeholder as url if the frontpage path is being resolved.

⚠ Since this is a behavior change I propose to make it opt-in via an optional argument keepFrontpagePath.

Remaining tasks

  1. ✓ Write Code - decide on approach regarding opt-in or nah
  2. ✓ Write Tests - have been written using LLM support - the rest by a grumpy organic developer :)
  3. Review
  4. Profit

User interface changes

None

API changes

None - so far only opt-in change planned. The introduced argument might affect code that integrates with the languageSwither DataProducer because 'keepFrontpagePath' has to be mapped in the builder.

Data model changes

None

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

das-peter created an issue. See original summary.

das-peter’s picture

Issue summary: View changes
Status: Needs work » Needs review

First stab at this.
Was pretty straight forward - can't use path matcher because we're not running in a routing subrequest it seems.
But using the same logic as the pathMatcher to check for the frontpage works fine.
The tests have been written using LLM support - the rest by a grumpy organic developer :)