diff options
author | Dries Buytaert <dries@buytaert.net> | 2006-08-29 18:43:26 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2006-08-29 18:43:26 +0000 |
commit | 5524604a951f1158ea33584630c0811c217a1346 (patch) | |
tree | df956d335db604bc16f9e627be3f88b2f26884b1 /modules/path | |
parent | 78ee75f1a2ecc6a788dcf697d36783798ecbbe12 (diff) | |
download | brdo-5524604a951f1158ea33584630c0811c217a1346.tar.gz brdo-5524604a951f1158ea33584630c0811c217a1346.tar.bz2 |
- Patch #68418 by Moshe et al: clean up node submit hooks.
Diffstat (limited to 'modules/path')
-rw-r--r-- | modules/path/path.module | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/modules/path/path.module b/modules/path/path.module index 2a4b10ee7..760e5b02f 100644 --- a/modules/path/path.module +++ b/modules/path/path.module @@ -209,16 +209,6 @@ function path_form($edit = '') { function path_nodeapi(&$node, $op, $arg) { if (user_access('create url aliases') || user_access('administer url aliases')) { switch ($op) { - case 'validate': - $node->path = trim($node->path); - if ($node->path && !valid_url($node->path)) { - form_set_error('path', t('The path is invalid.')); - } - else if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE dst = '%s' AND src != '%s'", $node->path, "node/$node->nid"))) { - form_set_error('path', t('The path is already in use.')); - } - break; - case 'load': $path = "node/$node->nid"; // We don't use drupal_get_path_alias() to avoid custom rewrite functions. @@ -228,27 +218,37 @@ function path_nodeapi(&$node, $op, $arg) { $node->path = db_result($result); } break; + } + } +} - case 'insert': - // Don't try to insert if path is NULL. We may have already set - // the alias ahead of time. - if ($node->path) { - path_set_alias("node/$node->nid", $node->path); - } - break; - - case 'update': - path_set_alias("node/$node->nid", $node->path, $node->pid); - break; +function path_node_delete_confirm_submit($form_id, $form_values) { + $path = 'node/'. $form_values['node']->nid; + if (drupal_get_path_alias($path) != $path) { + path_set_alias($path); + } +} - case 'delete': - $path = "node/$node->nid"; - if (drupal_get_path_alias($path) != $path) { - path_set_alias($path); - } - break; +function path_node_submit($form_id, $node) { + if ($node->is_new) { + // Don't try to insert if path is NULL. We may have already set the alias ahead of time. + if ($node->path) { + path_set_alias("node/$node->nid", $node->path); } } + else { + path_set_alias("node/$node->nid", $node->path, $node->pid); + } +} + +function path_node_validate($form_id, $node) { + $node['path'] = trim($node['path']); + if ($node['path'] && !valid_url($node['path'])) { + form_set_error('path', t('The path is invalid.')); + } + else if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE dst = '%s' AND src != '%s'", $node['path'], 'node/'. $node['nid']))) { + form_set_error('path', t('The path is already in use.')); + } } /** @@ -256,6 +256,12 @@ function path_nodeapi(&$node, $op, $arg) { */ function path_form_alter($form_id, &$form) { if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) { + + if (user_access('create url aliases')) { + $form['#validate']['path_node_validate'] = array(); + $form['#submit']['path_node_submit'] = array(); + } + $path = $form['#node']->path; $form['path'] = array( '#type' => 'fieldset', @@ -280,6 +286,10 @@ function path_form_alter($form_id, &$form) { ); } } + + if ($form_id == 'node_delete_confirm') { + $form['#submit']['path_node_delete_confirm_submit'] = array(); + } } |