Using workbench moderation and the following:

1. an entity translated content type using title module top replace the node title
2. an entity translated taxonomy vocabulary using title module to replace the term name,
- create one term and translate it (myterm-english-name | myterm-french-name)
3. create a field on the node which references (via entity reference) the vocabulary in #2
4. configure pathauto to use the name of the taxonomy term in the url
5. create a node and translate it (my english title | my french title) and reference the term from #2

The end result will be the English url is fine but the French url will contain the English term name:

fr/myterm-english-name/my-french-title

Disable moderation, regenerate the alias and the result will be fine:

fr/myterm-french-name/my-french-title

What happens is that on the first node_save from the form submit pathauto works fine. Then when workbench_moderation_store calls node_save($live_revision) a second time it triggers pathauto again and this time for some reason (maybe pathauto, entity_translation?) it incorrectly gets the entity language and the path will get the term name from the default language instead of the translated one.

Whew, confusing I know. But I am thinking calling pathauto a second time is likely unnessary and so there is a fix proposed in [#1949728|1] which involves adding one line just before the node_save which tells pathauto not to run again:

1581   unset($taxonomy_index_flag[$node->nid]);
1582   $live_revision->path['pathauto'] = 0;
1583   // Save the node.
1584   node_save($live_revision);
1585 }

This one liner fixes my issue as well as the issue referenced above, and even though it is a bit of a hack it may not be a bad idea even for performance reasons unless there is a good reason to have workbench_moderation re-run pathauto. Also, I know workbench is currently being re-factored so maybe this is just an FYI that perhaps calling node_save within workbench could be avoided altogether.

Comments

joel_osc’s picture

Status: Active » Needs review
StatusFileSize
new550 bytes

Here is a patch if anyone needs it.

joel_osc’s picture

StatusFileSize
new1.4 KB

There is a little more to this in that with pathauto persist functionality built in to pathauto now by using my method above pathauto entity state will be disabled so that if you try bulk update alias it will not run on your nodes. Here is a 'better' solution but I don't think it is a good solution...it works for now though.

This may be related too #1852244: Setting path to default Pathauto value and potentially a better approach if it works under all the same conditions (entity translation in particular). Although, I am still not a fan of running pathauto twice on every node save.

dnlt’s picture

Hi joel_osc, your patch really makes all aliases generate nicely, but in my case it makes my drafts get directly published, avoiding the moderation process.
Can I do some test to verify why?

joel_osc’s picture

Hmm, interesting - I am not really sure why turning off pathauto would on the second node_save would cause this. That being said, in looking at it my patch above is not much of a solution to the entire issue - really just a workaround. One patch you may want to try that could be related can be found here: #1925848: Pathauto generates language neutral alias on node creation - I believe it may help the issue with the second node_save's call to entity_language coming back with up 'und'.

Although, It would be nice if the second node_save was not done at all, but I came across another issue and this module's maintainer is well aware of this and looking to D8's architecture for a solution. In light of this and the fact that my solution is merely a workaround I think I am going to close this issue off. Perhaps a good solution will come out of the issue I mentioned above.

And also note that path_auto persist is not built in to pathauto - I had not realized that we applied a patch that added this functionality. Ref: #936222: Merge in pathauto_persist module functionality to prevent losing manual aliases with node_save() calls

dnlt’s picture

Status: Needs review » Closed (won't fix)

Thanks a lot, joel_osc. We'll have a look at that issue and try to contribute. I think we are missing some details about what really happens.
Thanks again, we'll keep updated the affected threads.