diff --git a/pathauto.module b/pathauto.module index 1875caa..c887e47 100644 --- a/pathauto.module +++ b/pathauto.module @@ -427,6 +427,25 @@ function path_field_extra_fields() { } /** + * Returns the language code of the given entity. + * + * Backward compatibility layer to ensure that installations running an outdated + * version of core where entity_language() is not avilable do not break. + */ +function pathauto_entity_language($entity_type, $entity, $skip_fallback = FALSE) { + $langcode = NULL; + + if (function_exists('entity_language')) { + $langcode = entity_language($entity_type, $entity); + } + elseif (!$skip_fallback && !empty($entity->language)) { + $langcode = $entity->language; + } + + return !empty($langcode) ? $langcode : LANGUAGE_NONE; +} + +/** * @name pathauto_node Pathauto integration for the core node module. * @{ */ @@ -461,7 +480,8 @@ function pathauto_node_delete($node) { */ function pathauto_form_node_form_alter(&$form, &$form_state) { $node = $form_state['node']; - pathauto_field_attach_form('node', $node, $form, $form_state, $node->language); + $langcode = pathauto_entity_language('node', $node); + pathauto_field_attach_form('node', $node, $form, $form_state, $langcode); } /** @@ -492,9 +512,7 @@ function pathauto_node_update_alias(stdClass $node, $op, array $options = array( return; } - $options += array( - 'language' => !empty($node->language) ? $node->language : LANGUAGE_NONE, - ); + $options += array('language' => pathauto_entity_language('node', $node)); // Skip processing if the node has no pattern. if (!pathauto_pattern_load_by_entity('node', $node->type, $options['language'])) { @@ -574,7 +592,7 @@ function pathauto_taxonomy_term_delete($term) { */ function pathauto_form_taxonomy_form_term_alter(&$form, $form_state) { $term = $form_state['term']; - $langcode = !empty($term->language) ? $term->language : LANGUAGE_NONE; + $langcode = pathauto_entity_language('taxonomy_term', $term); pathauto_field_attach_form('taxonomy_term', $term, $form, $form_state, $langcode); } @@ -596,7 +614,7 @@ function pathauto_taxonomy_term_update_alias(stdClass $term, $op, array $options $options += array( 'alias children' => FALSE, - 'language' => !empty($term->language) ? $term->language : LANGUAGE_NONE, + 'language' => pathauto_entity_language('taxonomy_term', $term), ); $module = 'taxonomy_term'; @@ -727,7 +745,9 @@ function pathauto_user_update_alias(stdClass $account, $op, array $options = arr $options += array( 'alias blog' => module_exists('blog'), - 'language' => LANGUAGE_NONE, + // $user->language is not the user entity language, thus we need to skip the + // backward-compatibility fallback. + 'language' => pathauto_entity_language('user', $account, TRUE), ); // Skip processing if the account has no pattern.