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?

Files: 
CommentFileSizeAuthor
#2 pathauto-2030983-respect-entity-path-language-2.patch1016 bytesq0rban
PASSED: [[SimpleTest]]: [MySQL] 322 pass(es).
[ View ]

Comments

Dave Reid’s picture

Using $entity->path['language'] present first, then falling back to entity_language() seems reasonable.

q0rban’s picture

Status:Active» Needs review
StatusFileSize
new1016 bytes
PASSED: [[SimpleTest]]: [MySQL] 322 pass(es).
[ View ]

Attached patch fixes the issue for me.

pablojais’s picture

I'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,

  [title] => basic title
  [nid] => 21
  [language] => es
  [title_field] => Array (
    [en] => Array ([0] => Array ([value] => english title, ...), ...)
    [es] => Array ([0] => Array ([value] => spanish title, ...), ...)

and autogenerated aliases (en/english-title and es/spanish-title). However, when I run this script:

<?php
  $node
= node_load(21);
 
$node->title_field[en][0] = "new english title";
 
$node->path['pathauto'] = TRUE;
 
$node->path['language'] = 'it';
 
node_save($node);
?>

I get

  [title] => new english title
  [nid] => 21
  [language] => es
  [title_field] => Array (
    [en] => Array ([0] => Array ([value] => new english title, ...), ...)
    [es] => Array ([0] => Array ([value] => new english title, ...), ...)
aliases: en/new-english-title and es/spanish-title

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!

PedroMiguel’s picture

Issue summary:View changes

q0rban patch works well for me, thanks, all my translated paths are created.

kpyan8s’s picture

The path may apply by running:

curl -sL https://www.drupal.org/files/pathauto-2030983-respect-entity-path-language-2.patch | patch -p1
kopeboy’s picture

Should 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

Dave Reid’s picture

Issue tags:+Needs tests
Dave Reid’s picture

Dave Reid’s picture