From a12152309a64b5c3b9ea6a41e8da2baa9971f612 Mon Sep 17 00:00:00 2001 From: David Rothstein Date: Sat, 9 Jun 2012 15:51:03 -0400 Subject: Issue #1495648 by plach: Introduce entity language support. --- modules/path/path.module | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'modules/path') diff --git a/modules/path/path.module b/modules/path/path.module index 9df498865..1bb06f42b 100644 --- a/modules/path/path.module +++ b/modules/path/path.module @@ -99,8 +99,9 @@ function path_form_node_form_alter(&$form, $form_state) { $path = array(); if (!empty($form['#node']->nid)) { $conditions = array('source' => 'node/' . $form['#node']->nid); - if ($form['#node']->language != LANGUAGE_NONE) { - $conditions['language'] = $form['#node']->language; + $langcode = entity_language('node', $form['#node']); + if ($langcode != LANGUAGE_NONE) { + $conditions['language'] = $langcode; } $path = path_load($conditions); if ($path === FALSE) { @@ -111,7 +112,7 @@ function path_form_node_form_alter(&$form, $form_state) { 'pid' => NULL, 'source' => isset($form['#node']->nid) ? 'node/' . $form['#node']->nid : NULL, 'alias' => '', - 'language' => isset($form['#node']->language) ? $form['#node']->language : LANGUAGE_NONE, + 'language' => isset($langcode) ? $langcode : LANGUAGE_NONE, ); $form['path'] = array( @@ -192,8 +193,9 @@ function path_node_insert($node) { // Only save a non-empty alias. if (!empty($path['alias'])) { // Ensure fields for programmatic executions. + $langcode = entity_language('node', $node); $path['source'] = 'node/' . $node->nid; - $path['language'] = isset($node->language) ? $node->language : LANGUAGE_NONE; + $path['language'] = isset($langcode) ? $langcode : LANGUAGE_NONE; path_save($path); } } @@ -210,13 +212,7 @@ function path_node_update($node) { if (!empty($path['pid']) && empty($path['alias'])) { path_delete($path['pid']); } - // Only save a non-empty alias. - if (!empty($path['alias'])) { - // Ensure fields for programmatic executions. - $path['source'] = 'node/' . $node->nid; - $path['language'] = isset($node->language) ? $node->language : LANGUAGE_NONE; - path_save($path); - } + path_node_insert($node); } } @@ -234,7 +230,10 @@ function path_node_delete($node) { function path_form_taxonomy_form_term_alter(&$form, $form_state) { // Make sure this does not show up on the delete confirmation form. if (empty($form_state['confirm_delete'])) { - $path = (isset($form['#term']['tid']) ? path_load('taxonomy/term/' . $form['#term']['tid']) : array()); + $langcode = entity_language('taxonomy_term', (object) $form['#term']); + $langcode = !empty($langcode) ? $langcode : LANGUAGE_NONE; + $conditions = array('source' => 'taxonomy/term/' . $form['#term']['tid'], 'language' => $langcode); + $path = (isset($form['#term']['tid']) ? path_load($conditions) : array()); if ($path === FALSE) { $path = array(); } @@ -242,7 +241,7 @@ function path_form_taxonomy_form_term_alter(&$form, $form_state) { 'pid' => NULL, 'source' => isset($form['#term']['tid']) ? 'taxonomy/term/' . $form['#term']['tid'] : NULL, 'alias' => '', - 'language' => LANGUAGE_NONE, + 'language' => $langcode, ); $form['path'] = array( '#access' => user_access('create url aliases') || user_access('administer url aliases'), @@ -274,7 +273,10 @@ function path_taxonomy_term_insert($term) { if (!empty($path['alias'])) { // Ensure fields for programmatic executions. $path['source'] = 'taxonomy/term/' . $term->tid; - $path['language'] = LANGUAGE_NONE; + // Core does not provide a way to store the term language but contrib + // modules can do it so we need to take this into account. + $langcode = entity_language('taxonomy_term', $term); + $path['language'] = !empty($langcode) ? $langcode : LANGUAGE_NONE; path_save($path); } } @@ -295,7 +297,10 @@ function path_taxonomy_term_update($term) { if (!empty($path['alias'])) { // Ensure fields for programmatic executions. $path['source'] = 'taxonomy/term/' . $term->tid; - $path['language'] = LANGUAGE_NONE; + // Core does not provide a way to store the term language but contrib + // modules can do it so we need to take this into account. + $langcode = entity_language('taxonomy_term', $term); + $path['language'] = !empty($langcode) ? $langcode : LANGUAGE_NONE; path_save($path); } } -- cgit v1.2.3