Problem/Motivation

When Entity Mesh processes internal links that don't have a language prefix in their path (e.g., /foo/bar instead of /en/foo/bar), the redirect lookup fails because it uses a NULL langcode.

This happens because processInternalHref() extracts the langcode from the URL path using getLangcodeFromPath(). When the path has no language prefix, it returns NULL. This NULL langcode is then passed to ifRedirectionForPath(), which fails to find redirects that are stored with a specific language (e.g., 'en').

As a result, valid links that have redirects configured are incorrectly marked as broken-link instead of redirected-link.

Steps to reproduce

  1. Have a multilingual Drupal site with the Redirect module enabled
  2. Create a redirect from foo/bar to /node/1 with language set to 'en'
  3. Create a node (in English) with a link to /foo/bar (without language prefix)
  4. Process the node with Entity Mesh
  5. Check the entity_mesh table - the link will be marked as broken-link instead of redirected-link

Proposed resolution

Add an optional $fallback_langcode parameter to processInternalHref() that defaults to NULL. When the path doesn't contain a language prefix, use this fallback langcode (typically the source entity's langcode) for redirect and alias lookups.

Remaining tasks

  • Review MR
  • Add/update tests for the new behavior

API changes

The protected method processInternalHref() now accepts an optional second parameter:

protected function processInternalHref(TargetInterface $target, ?string $fallback_langcode = NULL)

This is backwards compatible - existing code calling this method without the second parameter will continue to work.

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

juanjol created an issue. See original summary.

juanjol’s picture

Issue summary: View changes
juanjol’s picture

Version: 1.2.4 » 1.x-dev

juanjol’s picture

Status: Active » Needs review

eduardo morales alberti made their first commit to this issue’s fork.

eduardo morales alberti’s picture

Status: Needs review » Needs work

It is working but it needs tests

eduardo morales alberti’s picture

Added testing coverage (fallback langcode default), as we can not install the redirect module on PHPUnit tests

eduardo morales alberti’s picture

Status: Needs work » Reviewed & tested by the community

Tested in an environment with module redirect.

eduardo morales alberti’s picture

Status: Reviewed & tested by the community » Fixed

Merged and Fixed! Thank you!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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