diff --git a/xmlsitemap.module b/xmlsitemap.module index 118f0e0..442f511 100644 --- a/xmlsitemap.module +++ b/xmlsitemap.module @@ -603,10 +603,13 @@ function xmlsitemap_link_save(array $link, array $context = array()) { $link['changecount'] = 0; } + $link_keys = array('type', 'id'); + // If entity translation exists and the link has a language we need to add the // language to the query to fetch the unique / language specific link. - if (module_exists('entity_translation') && !empty($link['language'])) { + if (module_exists('entity_translation') && entity_get_info($link['type']) && entity_translation_enabled($link['type']) && !empty($link['language'])) { $existing = db_query_range("SELECT loc, access, status, lastmod, priority, changefreq, changecount, language FROM {xmlsitemap} WHERE type = :type AND id = :id AND language = :language", 0, 1, array(':type' => $link['type'], ':id' => $link['id'], ':language' => $link['language']))->fetchAssoc(); + $link_keys[] = 'language'; } else { $existing = db_query_range("SELECT loc, access, status, lastmod, priority, changefreq, changecount, language FROM {xmlsitemap} WHERE type = :type AND id = :id", 0, 1, array(':type' => $link['type'], ':id' => $link['id']))->fetchAssoc(); @@ -619,7 +622,7 @@ function xmlsitemap_link_save(array $link, array $context = array()) { // Save the link and allow other modules to respond to the link being saved. if ($existing) { - drupal_write_record('xmlsitemap', $link, array('type', 'id', 'language')); + drupal_write_record('xmlsitemap', $link, $link_keys); module_invoke_all('xmlsitemap_link_update', $link, $context); } else { diff --git a/xmlsitemap_node/xmlsitemap_node.module b/xmlsitemap_node/xmlsitemap_node.module index ef83ee2..1da2086 100644 --- a/xmlsitemap_node/xmlsitemap_node.module +++ b/xmlsitemap_node/xmlsitemap_node.module @@ -85,6 +85,20 @@ function xmlsitemap_node_node_delete(stdClass $node) { } /** + * Implements hook_entity_translation_delete(). + */ +function xmlsitemap_node_entity_translation_delete($entity_type, $entity, $langcode) { + if ($entity_type == 'node') { + $conditions = array( + 'type' => 'node', + 'id' => $entity->nid, + 'language' => $langcode, + ); + xmlsitemap_link_delete_multiple($conditions); + } +} + +/** * Implements hook_comment_update(). */ function xmlsitemap_node_comment_update(stdClass $comment) { diff --git a/xmlsitemap_taxonomy/xmlsitemap_taxonomy.module b/xmlsitemap_taxonomy/xmlsitemap_taxonomy.module index 8bc7b43..0603165 100644 --- a/xmlsitemap_taxonomy/xmlsitemap_taxonomy.module +++ b/xmlsitemap_taxonomy/xmlsitemap_taxonomy.module @@ -144,6 +144,21 @@ function xmlsitemap_taxonomy_term_delete(stdClass $term) { } /** + * Implements hook_entity_translation_delete(). + */ +function xmlsitemap_node_entity_translation_delete($entity_type, $entity, $langcode) { + if ($entity_type == 'taxonomy_term') { + $conditions = array( + 'type' => $entity_type, + 'id' => $entity->tid, + 'language' => $langcode, + ); + xmlsitemap_link_delete_multiple($conditions); + } +} + + +/** * Implements hook_field_extra_fields(). */ function xmlsitemap_taxonomy_field_extra_fields() {