Hi,
I had an issue with pathauto, many of my nodes are bugged.
When I load some node, $entity->path is a string and not an array; so in the function pathauto_field_attach_form() when we check if the $entity->path['pathauto'] exist, the result is wrong ($entity->path['pathauto'] return the first letter of the string $entity->path)
It doesn't enter in the if when it should.
// pathauto.module
if (!isset($entity->path['pathauto'])) {
if (!empty($id)) {
module_load_include('inc', 'pathauto');
$uri = entity_uri($entity_type, $entity);
$path = drupal_get_path_alias($uri['path'], $langcode);
$pathauto_alias = pathauto_create_alias($entity_type, 'return', $uri['path'], array($entity_type => $entity), $bundle, $langcode);
$entity->path['pathauto'] = ($path != $uri['path'] && $path == $pathauto_alias);
}
else {
$entity->path['pathauto'] = TRUE;
}
}
$entity->path['pathauto'] = the first letter of $entity->path so the default_value = the letter = false for the Drupal API
// pathauto.module
$form['path']['pathauto'] = array(
'#type' => 'checkbox',
'#title' => t('Generate automatic URL alias'),
'#default_value' => $entity->path['pathauto'],
'#description' => t('Uncheck this to create a custom alias below.'),
'#weight' => -1,
);
I don't understand why $entity->path isn't an array ?
Then; when I save the node, the $entity->path become an array and pathauto works well for this node.
My mainly issue is when the Drupal path is equal to the pathauto pattern, the checkbox is not checked.
By adding this code in pathauto_field_attach_form(), the issue is fixed :
// pathauto.module
$pattern = pathauto_pattern_load_by_entity($entity_type, $bundle, $langcode);
if (empty($pattern)) {
return;
}
if (!is_array($entity->path)) {
$entity->path = array();
}
if (!isset($entity->path['pathauto'])) {
if (!empty($id)) {
module_load_include('inc', 'pathauto');
$uri = entity_uri($entity_type, $entity);
$path = drupal_get_path_alias($uri['path'], $langcode);
$pathauto_alias = pathauto_create_alias($entity_type, 'return', $uri['path'], array($entity_type => $entity), $bundle, $langcode);
$entity->path['pathauto'] = ($path != $uri['path'] && $path == $pathauto_alias);
}
else {
$entity->path['pathauto'] = TRUE;
}
}
Do you understand from where comes my issue ?
Thank you in advance.
Comments
Comment #1
Dave ReidWhat is $entity->path actually contain before the pathauto hook runs? What kind of entity type is it?
Comment #2
cwoky CreditAttribution: cwoky commentedHello,
The entity is a node.
When $entity->path is a string, it is directly the path of my node. (Exemple : my-node-title.html)
Comment #3
Dave ReidDrupal core doesn't put any string in $node->path by default. It has to be some other module doing this? Can you reproduce this with just a fresh install of Core + Pathauto?
Comment #4
cwoky CreditAttribution: cwoky commentedI have a lot a module enable and I can't reproduice the issue with a new content.
When I save a node, $entity->path['pathauto'] is correctly instanciate.
Comment #5
cwoky CreditAttribution: cwoky commentedWe have not managed to reproduce the bug on a fresh install.
Comment #6
dshields CreditAttribution: dshields at OpenConcept Consulting Inc. commentedFieldable Panels Panes does this.