Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This is related to the core issue #1499532: Cannot programmatically specify node path alias language. The current code added in #1155132: Add Entity Translation support to Pathauto auto detects the language of the path based on the entity, preventing a programmatic setting of the language. I think Pathauto should respect $entity->path['language']
if it is present. Thoughts?
Comment | File | Size | Author |
---|---|---|---|
#2 | pathauto-2030983-respect-entity-path-language-2.patch | 1016 bytes | q0rban |
Comments
Comment #1
Dave ReidUsing $entity->path['language'] present first, then falling back to entity_language() seems reasonable.
Comment #2
q0rban CreditAttribution: q0rban commentedAttached patch fixes the issue for me.
Comment #3
pablojais CreditAttribution: pablojais commentedI'm not entirely sure why this happens, but applying this patch to the stable version causes a side effect. I have a node with, say,
and autogenerated aliases (en/english-title and es/spanish-title). However, when I run this script:
I get
I noticed that this happened when the replacement pattern was [node:title] but not when it's [node:title_field]. Of course I should use the second one, but I don't think this should happen anyway. I managed to track down the issue up to the
$alias = token_replace($pattern, $data, ...);
in line 359 of the stable version. The titles change somewhere during that call. I know it's not a lot of info, but I can't test this in the dev version right now.Thanks!
Comment #4
PedroMiguel CreditAttribution: PedroMiguel commentedq0rban patch works well for me, thanks, all my translated paths are created.
Comment #5
kpyan8s CreditAttribution: kpyan8s commentedThe path may apply by running:
Comment #6
kopeboy CreditAttribution: kopeboy commentedShould I use this other patch https://www.drupal.org/node/1155132 together with this to have the pathauto patterns work with all languages (when using Entity Translation?
Or this is just a non-required add-on to that patch?
Thanks
Comment #7
Dave ReidComment #8
Dave ReidComment #9
Dave ReidComment #10
joelpittetI've been using this and it seems to work for my needs.
Comment #11
Simon Georges CreditAttribution: Simon Georges at Makina Corpus commentedIt seems several people have it working for their needs.
Comment #12
joseph.olstadfor us the patch above didn't help.
english / french generating /scripting node creates and translations, english ok path alias is there, french nothing.
We are programmatically /script creating nodes and adding entity translation translation using the entity entity_metadata_wrapper . What we found in our D7 setup is that after saving the source language node (calling the entity_metadata_wrapper save function) pathauto_state was changed or removed for that node, however a path auto was automatically generated for english. What our issue was is that we found that there was no french auto generated alias, and the pathauto_state was deleted for the entity_id (same id for french and english as its one node, field translation/entity translation).
So , right after the entity_metadata_wrapper save() for english, we insert the pathauto_state
Then we create the translation of the english.
after all this, the path alias gets created for french and the pathauto_state is set for this entity.
Not sure why this is, however, after much tests of various patches , the easiest way was the brute force way.
Comment #13
Chris Matthews CreditAttribution: Chris Matthews commentedPer the comment in #12 it looks like this issue still needs work.