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
- Have a multilingual Drupal site with the Redirect module enabled
- Create a redirect from
foo/barto/node/1with language set to 'en' - Create a node (in English) with a link to
/foo/bar(without language prefix) - Process the node with Entity Mesh
- Check the entity_mesh table - the link will be marked as
broken-linkinstead ofredirected-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.
Issue fork entity_mesh-3570211
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
Comment #2
juanjolComment #3
juanjolComment #5
juanjolComment #7
eduardo morales albertiIt is working but it needs tests
Comment #8
eduardo morales albertiAdded testing coverage (fallback langcode default), as we can not install the redirect module on PHPUnit tests
Comment #9
eduardo morales albertiTested in an environment with module redirect.
Comment #11
eduardo morales albertiMerged and Fixed! Thank you!