I have numerous nodes with no language set. When pathauto generates a path, it is saved with the language column NULL. The alias doesn't work at all (node/[nid] is not translated to foo/bar). Forcing LANGUAGE_NONE (e.g. und) into that table field makes the path work.

The following is working for me:

diff --git a/modules/pathauto/pathauto.inc b/modules/pathauto/pathauto.inc
index 0633386..bbb7271 100644
--- a/modules/pathauto/pathauto.inc
+++ b/modules/pathauto/pathauto.inc
@@ -510,6 +510,9 @@ function _pathauto_set_alias(array $path, $existing_alias = NULL, $op = NULL) {
     }
 
     // Save the path array.
+    if (empty($path['language']) ) {
+      $path['language'] = empty($path['original']) ? LANGUAGE_NONE : $path['original']['language'];
+    }
     path_save($path);
 
     if ($verbose) {

#1234924 appears related.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Status: Active » Postponed (maintainer needs more info)

I fail to see how this could be happening unless something is specifically passing in $options['language'] = NULL (which no Pathauto code does). Are the {url_alias}.language values actually NULL or are they an empty string?

function pathauto_node_update_alias(stdClass $node, $op, array $options = array()) {
  ...

  $options += array(
    'language' => isset($node->language) ? $node->language : LANGUAGE_NONE,
  );

  // Skip processing if the node has no pattern.
  if (!pathauto_pattern_load_by_entity('node', $node->type, $options['language'])) {
    return;
  }

  module_load_include('inc', 'pathauto');
  $uri = entity_uri('node', $node);
  pathauto_create_alias('node', $op, $uri['path'], array('node' => $node), $node->type, $options['language']);
}

#1234924: Option to always force language = All? does not seem related at all.

Dave Reid’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
B-Prod’s picture

Status: Closed (cannot reproduce) » Needs review
FileSize
497 bytes

This issue still exists!

How to reproduce (not sure all the steps are really necessary):

  1. Set up a Drupal installation using a language different than EN.
  2. Activate pathauto
  3. Deactivate EN
  4. Set page pattern to [node:title]
  5. Create a new page with "test" as title and save it

What I see / would like to see:
When viewing the page, the URL is still "node/nid" and not "test".
When editing the node, the pathauto checkbox is unchecked and the path field is filled with "test".

Digging into this issue
Sometimes, I do not know why, the node->language is an empty string, despite of the installed language has a prefix. In such cases, the check at line 465 (function pathauto_node_update_alias()) does not modify the prefix, and the column 'language' in the url_alias table is empty.

So when we call drupal_lookup_alias(), the system does not find the alias because the check is not made using isset() construct ['' return TRUE] but testing the $path_language variable ['' return FALSE].

So the main issue is probably in Drupal core, because node language should not contain an empty string but a language prefix or 'und'. I failed finding where it goes wrong.
About pathauto, modifying the isset() check can corrects that. The question is then: should the LANGUAGE_NONE be used or the default language? The patch below use the neutral language because it represents less code to modify.

Dave Reid’s picture

Version: 7.x-1.0-rc2 » 7.x-1.x-dev
Status: Needs review » Needs work

We can just convert this to use !empty() rather than isset() and it works for all cases.

Dave Reid’s picture

Status: Needs work » Needs review
FileSize
1.45 KB
Dave Reid’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.