diff --git a/pathauto.module b/pathauto.module index 9bb132d..0296ed7 100644 --- a/pathauto.module +++ b/pathauto.module @@ -374,6 +374,24 @@ function pathauto_entity_presave($entity, $entity_type) { $entity->path['alias'] = $entity->path['old_alias']; } + // Prevent rebuilding custom paths from node_save + // when syncing translations + if (pathauto_type_applied($entity_type) && !isset($entity->path['pathauto']) && !empty($entity->language)) { + $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. // @see http://drupal.org/node/1328180 @@ -893,5 +911,22 @@ function pathauto_blog_update_alias(stdClass $account, $op, array $options = arr } /** + * Check whether pathauto is applied to entity type. + * + * @param string $type + */ +function pathauto_type_applied($type) { + $all_settings = module_invoke_all('pathauto', 'settings'); + $entity_types = array('node', 'user', 'taxonomy_term'); + foreach ($all_settings as $setting) { + if (isset($setting->entity_type)) { + $entity_types[] = $setting->entity_type; + } + } + + return in_array($type, $entity_types); +} + +/** * @} End of "name pathauto_user". */