diff --git a/pathauto.module b/pathauto.module index fbbdae3..2ed2df2 100644 --- a/pathauto.module +++ b/pathauto.module @@ -351,7 +351,7 @@ function pathauto_field_attach_form($entity_type, $entity, &$form, &$form_state, /** * Implements hook_entity_presave(). */ -function pathauto_entity_presave($entity, $type) { +function pathauto_entity_presave($entity, $entity_type) { // About to be saved (before insert/update) if (!empty($entity->path['pathauto']) && isset($entity->path['old_alias']) && $entity->path['alias'] == '' && $entity->path['old_alias'] != '') { @@ -363,6 +363,24 @@ function pathauto_entity_presave($entity, $type) { */ $entity->path['alias'] = $entity->path['old_alias']; } + + // Prevent rebuilding custom paths from node_save + // when syncing translations + if (!isset($entity->path['pathauto'])) { + $langcode = $entity->language; + list($id, , $bundle) = entity_extract_ids($entity_type, $entity); + + if (!empty($id)) { + module_load_include('inc', 'pathauto'); + $uri = entity_uri($entity_type, $entity); + $path = drupal_get_path_alias($uri['path'], $langcode); + $pathauto_alias = pathauto_create_alias($entity_type, 'return', $uri['path'], array($entity_type => $entity), $bundle, $langcode); + $entity->path['pathauto'] = ($path != $uri['path'] && $path == $pathauto_alias); + } + else { + $entity->path['pathauto'] = TRUE; + } + } // Help prevent errors with progromatically creating entities by defining // path['alias'] as an empty string.