Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#5 | 1254912-pathauto-empty-string-langcode.patch | 1.45 KB | Dave Reid |
#3 | pathauto-null-language-prefix-instead-of-language-none-1254912-3.patch | 497 bytes | B-Prod |
Comments
Comment #1
Dave ReidI 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?
#1234924: Option to always force language = All? does not seem related at all.
Comment #2
Dave ReidComment #3
B-Prod CreditAttribution: B-Prod commentedThis issue still exists!
How to reproduce (not sure all the steps are really necessary):
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 (functionpathauto_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 usingisset()
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 theLANGUAGE_NONE
be used or the default language? The patch below use the neutral language because it represents less code to modify.Comment #4
Dave ReidWe can just convert this to use !empty() rather than isset() and it works for all cases.
Comment #5
Dave ReidComment #6
Dave ReidCommitted #5 to Git.
http://drupalcode.org/project/pathauto.git/commit/f4396d5