disable pathauto's default behaviour to recompute pathalias on every node edit

i don't know about you, but on sites where i set custom pathaliases for page nodes it becomes a problem when the site is handed off to someone else to admin and then forget to uncheck that box so the custom pathalias gets lost and links to that page then go 404. since i want to have root-level pathaliases, it's not easy to control via the standard pathauto settings.

here's a snippet you can put in your module to disable the checkbox if there is already an alias computed for that node. it's set to just operate on page node's but you can change that by changing "page_node_form" to whatever you like (or remove it entirely).


/**
* Implementation of hook_form_alter().
*/
function t1g_misc_form_alter(&$form, $form_state, $form_id) {
if ( $form_id == 'page_node_form' ) {
if ( !empty($form['path']['path']['#default_value']) ) {
$form['path']['pathauto_perform_alias']['#default_value'] = 0;
}
}
}

Comments

weight

Thanks for this. Since Pathauto's weight in systems table is set to 1, the module that has this code needs to be heavier than that.

you are correct-- the module

you are correct-- the module needs to have its weight set higher. here's the corresponding code from the t1g_misc.install file:

/*
* @file
* Implementation of hook_install().
*
* we need to set our weight to be < 0 so that our hooks are called before
* the core user module's are so we can see the new values before they are
* removed (otherwise we'd have to reload the data)
*/
function t1g_misc_install() {
$weight = db_result(db_query('SELECT MIN(weight) AS weight FROM {system} WHERE status = 1')) + 50;
db_query("UPDATE {system} SET weight = %d WHERE name = '%s'", $weight, 't1g_misc');
}

Doesnt seem to work for custom type

so would I replace

if ( $form_id == 'page_node_form' )

with

if ( $form_id == 'customcontentname_node_form' )

if I wanted the checkmark removed for all edit pages of a certain type? I did this, no response

(using drupal 6, path-auto, i18n site))

yes, you can update the

yes, you can update the $form_id check for whichever types of forms you would like it to apply to (or remove the check entirely if you wish, though that's a bit much for my usual needs).

oh, your exact code above doesnt work for any pages

still no go

what version of path-auto and drupal 6 were you using for this?

does this replace any code in path_auto.module, or just add to it?
(you didn't specify)

Thanks!

glowingtree (djfezzik@gmail.com)

any version of D6 should be

any version of D6 should be fine. make sure the module weight is set correctly (see comment above) and see if that resolves it for you.