Custom Entity Token [customentityname:original:label] Not Working in Bulk Pathauto URL Generation on Multilingual Site

Created on 31 December 2024, about 2 months ago

I am working on a multilingual Drupal site with a custom entity type. I have created a custom token [customentityname:original:label] to be used in Pathauto patterns. However, when I try to bulk generate URL aliases using Pathauto, the token [customentityname:original:label] is not working as expected.

Steps to Reproduce:
Create a custom entity type with multilingual support (e.g., "xyz").
Define the custom token [customentityname:original:label] for the entity in a custom plugin.
Configure Pathauto URL pattern to use the token [customentityname:original:label].
Attempt to bulk generate URL aliases for the custom entity using the Pathauto module.
The token [customentityname:original:label] does not resolve, and the URL aliases are not generated correctly.

Expected Behavior:
The [customentityname:original:label] token should resolve to the label of the custom entity in the default language during bulk URL alias generation.

Environment:
Drupal 10.x
Pathauto 8.x-1.13

🐛 Bug report
Status

Active

Version

1.13

Component

Code

Created by

🇮🇳India SAHIL ROHILLA01

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @SAHIL ROHILLA01
  • 🇮🇳India manpreet_singh

    Hello @sahil rohilla01

    Is this issue occur only during bulk generation, or will it also happen when creating individual entities?

    Thank you

  • 🇮🇳India SAHIL ROHILLA01

    @manpreet_singh , this isssue is coming during node creation and bulk pathauto pattern

  • 🇮🇳India DhruvR

    Hello @sahil,

    The issue you're facing with the [customentityname:original:label] token occurs because the original parameter isn’t designed to fetch the label in the default language. Instead, it retrieves the previous version of the entity’s label (or other field values) before any updates.

    For example, this feature is often used in scenarios like hook_presave to compare the current value with the previous one, such as:

    if ($entity->field_date->value != $entity->original->field_date->value) {  
      // Perform some logic.
    }  
    

    Unfortunately, this means the token won’t resolve the way you’re expecting for multilingual alias generation. If your goal is to use the default language label, you might need custom token logic to achieve that.

    Let me know if you’d like further guidance!

Production build 0.71.5 2024