Commit e95ceafa authored by Dave Reid's avatar Dave Reid
Browse files

Issue #1155132 by das-peter, plach, steinmb: Added Entity Translation support to Pathauto.

parent b75f1603
......@@ -389,6 +389,34 @@ function pathauto_action_info() {
return $info;
}
/**
* Returns the language code of the given entity.
*
* Backward compatibility layer to ensure that installations running an older
* version of core where entity_language() is not avilable do not break.
*
* @param string $entity_type
* An entity type.
* @param object $entity
* An entity object.
* @param bool $check_language_property
* A boolean if TRUE, will attempt to fetch the language code from
* $entity->language if the entity_language() function failed or does not
* exist. Default is TRUE.
*/
function pathauto_entity_language($entity_type, $entity, $check_language_property = TRUE) {
$langcode = NULL;
if (function_exists('entity_language')) {
$langcode = entity_language($entity_type, $entity);
}
elseif ($check_language_property && !empty($entity->language)) {
$langcode = $entity->language;
}
return !empty($langcode) ? $langcode : LANGUAGE_NONE;
}
if (!function_exists('path_field_extra_fields')) {
/**
* Implements hook_field_extra_fields() on behalf of path.module.
......@@ -461,7 +489,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 +521,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 +601,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);
}
......@@ -594,11 +621,6 @@ function pathauto_taxonomy_term_update_alias(stdClass $term, $op, array $options
return;
}
$options += array(
'alias children' => FALSE,
'language' => !empty($term->language) ? $term->language : LANGUAGE_NONE,
);
$module = 'taxonomy_term';
if ($term->vid == variable_get('forum_nav_vocabulary', '')) {
if (module_exists('forum')) {
......@@ -615,6 +637,11 @@ function pathauto_taxonomy_term_update_alias(stdClass $term, $op, array $options
$term->vocabulary_machine_name = $vocabulary->machine_name;
}
$options += array(
'alias children' => FALSE,
'language' => pathauto_entity_language('taxonomy_term', $term),
);
// Skip processing if the term has no pattern.
if (!pathauto_pattern_load_by_entity($module, $term->vocabulary_machine_name)) {
return;
......@@ -727,7 +754,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 property fallback check.
'language' => pathauto_entity_language('user', $account, FALSE),
);
// Skip processing if the account has no pattern.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment