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

Dave Reid’s picture

Status: Active » Postponed (maintainer needs more info)

What is $entity->path actually contain before the pathauto hook runs? What kind of entity type is it?

cwoky’s picture

Hello,

The entity is a node.
When $entity->path is a string, it is directly the path of my node. (Exemple : my-node-title.html)

Dave Reid’s picture

Drupal 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?

cwoky’s picture

I 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.

cwoky’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

We have not managed to reproduce the bug on a fresh install.

dshields’s picture