Hello there. I'm fairly new to the Drupal community, so I'm somewhat naive on how things work. I've noticed what appears to be an unwanted behavior with the pathauto module. While creating a new node in Drupal 5 RC1 (a page in this case), the option is given to set the URL path via the "URL path settings" field. When I do this, however, pathauto creates a second alias to match the node title. I could be missing something (and therefore this could be attributed to said naivety:), but it seems that if I enter a URL path while creating or updating a node, pathauto should not also create one.

CommentFileSizeAuthor
#4 pathauto_12.patch7.29 KBlbh

Comments

greggles’s picture

Status: Active » Closed (duplicate)

This is a duplicate request to http://drupal.org/node/32958

I'm not really sure how I feel about what pathauto should be doing in this situation, but I'd be willing to apply a patch that checks for a user entered alias and uses that instead of generating one at node creation/edit time. That seems like it might get complex, but I'd be interested in hearing ideas and seeing code (though not in writing code myself).

You may be interested in urlify module which has similar features but works better with manually editing the paths.

lbh’s picture

Oh sorry, I browsed to see if anybody else had taken note of this, but I must have overlooked the previous request. I'm actually pretty happy with pathauto module, I'd just prefer the option to have it not create an additional alias when a user defines one at node creation. I wasn't sure whether this was the desired behavior, or perhaps a bug. I suppose I could always remove the undesired aliases manually.

I'm new to both Drupal and coding, but I'm more than willing to give it a try (and embarrass myself). I seemed to have gotten something working, but I'd venture to guess there's plenty I'm overlooking. Perhaps there is a better way to do it, I'm not sure.

I created an option, so you can have the default behavior:

  $form["general"]["pathauto_manual_path"] = array('#type' => 'radios',
    '#title' => t('When a URL path is entered at node creation'), '#default_value' => variable_get('pathauto_manual_path', 1),
    '#options' => array(t('Use only the inserted alias'),
          t('Create a duplicate alias')),
    '#description' => t('What should pathauto do when a path alias is specified at node creation?'));

Then I wrapped the contents of the pathauto_create_alias() function in a conditional statement:

function pathauto_create_alias($module, $op, $placeholders, $src, $type = NULL) {

if (empty ($_POST['path']) or variable_get('pathauto_manual_path', 1)) {

  if (($op != 'bulkupdate') and variable_get('pathauto_verbose', FALSE)) {
    $verbose = TRUE;
  } 
  else {
    $verbose = FALSE;
  }

. . .
. . .

  return $alias;
}
}

I'm guessing that even if by some measure this is a decent way of doing this, there is probably a more Drupal specific variable than $_POST['path'].

greggles’s picture

Great start!

Can you post it as a patch?

http://drupal.org/diffandpatch

lbh’s picture

StatusFileSize
new7.29 KB

Thanks. I see why open source is addictive. :)
Anyway, here's the patch...

lbh’s picture

Status: Closed (duplicate) » Needs review
greggles’s picture

lbh - so, I'm looking into this and thinking about the if you created:

if (empty ($_POST['path']) or variable_get('pathauto_manual_path', 1)) {

My concern is how this will work if you are editing a post. If you are editing a node the path input box is populated. If you then change the title of the post (which would change the url) and leave the path box populated then your url will not be updated. I believe that is undesired behavior for the majority of users of pathauto.

I also think that the options could be improved (and therefore the underlying code would need to be improved). The options I would like:

1. If a path is entered at node creation/edit then do not automatically create one
2. If a path is entered at node creation/edit then ignore it and automatically create a path based on the pathauto patterns
3. If a path is entered at node creation/edit then create both the user-entered path and the path based on pathauto patterns as duplicates of each other

Perhaps there are more options - what do you think?

lbh’s picture

You're absolutely right, I didn't consider what would happen when editing a node. Sometimes it's annoying wanting to help but being a bit unexperienced (and sometimes confused). I think the Drupal-Dojo lessons should help though, little by little. Perhaps I'll play around with it some more; it might offer a good learning opportunity.

On a side note, I think that lately my brain is mostly consisted of mashed potatoes. :)

greggles’s picture

Status: Needs review » Needs work

So, just to be clear (since others are asking for this same feature) I think the only solution is to do a form_alter on the node_edit form, if the user can create aliases then insert a checkbox, if the checkbox is checked then use the alias provided in the manual alias creation form.

The checkbox default state should be off. Ideally some javascript should automatically check the box if the user types in the manual path alias box.

If the checkbox is checked and the path alias box is empty then it should probably still not create an alias.

greggles’s picture

Title: Duplicate aliases when creating a node and "manually" entering a URL path setting. » Provide an option at node creation/edit time to tell pathauto not to alias the node
Version: 5.x-1.x-dev » 5.x-2.x-dev

I'm changing the title to be more reflective of what the code should do.

As I think about this even more, we really just want pathauto to not create any aliases for these nodes. If you manually enter an alias or not...shouldn't matter to this option.

freeman-1’s picture

Greggles,

thanks for pointing me to this - from my "manual overrride" issue; and also suggesting URLify. Fact is I do a lot of programmatic node creation/update. So the Javascript edit-time feature doesn't help much.

I've been browsing the module code and I just couldn't tell why 'page' types can be set manually - e.g. the title is 'Page 11' but I could set the path as pager11s'. And it sticks. I couldn't do so for other types - story and CCK custom types.

If we could identify why this is so, would it be possible to replicate it to other types with some minor code changes ?

(I recall reading somewhere that the way to use pathauto was to leave the path field as blank if I wanted it to takeover and auto-generate the path URL alias. Otherwise, the URL alias will use whatever is typed there. I can't seem to dig out where I read that though)

greggles’s picture

If it "works" as you expect for pages, but not other nodes then pages are also broken - just in a different way than the other content types.

The right solution, in my mind, is still the checkbox idea that I outlined in #8.

freeman-1’s picture

I've fiddled around more with the pathauto module settings and it seems I could now create new nodes for other types with manually set paths. So it seems there are some (initial) state-related issues there, or I just need to more fully understand this module.

I'll open a new issue if I can replicate my original problem again.

greggles’s picture

Status: Needs work » Closed (duplicate)

N fixed via http://drupal.org/node/170673 so I'm marking this as a duplicate of that...

Yay features!

lbh’s picture

This is a great and simple solution!

I haven't really been around much except in the past couple of weeks. Strangely, one of my frustrations is that I'm perhaps not skilled enough to help out where I'd like. :)