diff options
Diffstat (limited to 'modules/path/path.module')
-rw-r--r-- | modules/path/path.module | 95 |
1 files changed, 54 insertions, 41 deletions
diff --git a/modules/path/path.module b/modules/path/path.module index e3eaa8de4..78933bcb5 100644 --- a/modules/path/path.module +++ b/modules/path/path.module @@ -117,53 +117,66 @@ function path_set_alias($path = NULL, $alias = NULL, $pid = NULL, $language = '' drupal_clear_path_cache(); } - /** - * Implementation of hook_nodeapi(). - * - * Allows URL aliases for nodes to be specified at node edit time rather - * than through the administrative interface. + * Implementation of hook_nodeapi_validate(). */ -function path_nodeapi(&$node, $op, $arg) { - // Permissions are required for everything except node loading. - if (user_access('create url aliases') || user_access('administer url aliases') || ($op == 'load')) { - $language = isset($node->language) ? $node->language : ''; - switch ($op) { - case 'validate': - if (isset($node->path)) { - $node->path = trim($node->path); - if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE dst = '%s' AND src != '%s' AND language = '%s'", $node->path, "node/$node->nid", $language))) { - form_set_error('path', t('The path is already in use.')); - } - } - break; +function path_nodeapi_validate(&$node, $arg) { + if (user_access('create url aliases') || user_access('administer url aliases')) { + if (isset($node->path)) { + $language = isset($node->language) ? $node->language : ''; + $node->path = trim($node->path); + if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE dst = '%s' AND src != '%s' AND language = '%s'", $node->path, "node/$node->nid", $language))) { + form_set_error('path', t('The path is already in use.')); + } + } + } +} - case 'load': - $path = 'node/' . $node->nid; - $alias = drupal_get_path_alias($path, $language); - if ($path != $alias) { - $node->path = $alias; - } - break; +/** + * Implementation of hook_nodeapi_load(). + */ +function path_nodeapi_load(&$node, $arg) { + $language = isset($node->language) ? $node->language : ''; + $path = 'node/' . $node->nid; + $alias = drupal_get_path_alias($path, $language); + if ($path != $alias) { + $node->path = $alias; + } +} - case 'insert': - // Don't try to insert if path is NULL. We may have already set - // the alias ahead of time. - if (isset($node->path)) { - path_set_alias('node/' . $node->nid, $node->path, NULL, $language); - } - break; +/** + * Implementation of hook_nodeapi_insert(). + */ +function path_nodeapi_insert(&$node, $arg) { + if (user_access('create url aliases') || user_access('administer url aliases')) { + $language = isset($node->language) ? $node->language : ''; + // Don't try to insert if path is NULL. We may have already set + // the alias ahead of time. + if (isset($node->path)) { + path_set_alias('node/' . $node->nid, $node->path, NULL, $language); + } + } +} - case 'update': - path_set_alias('node/' . $node->nid, isset($node->path) ? $node->path : NULL, isset($node->pid) ? $node->pid : NULL, $language); - break; +/** + * Implementation of hook_nodeapi_update(). + */ +function path_nodeapi_update(&$node, $arg) { + if (user_access('create url aliases') || user_access('administer url aliases')) { + $language = isset($node->language) ? $node->language : ''; + path_set_alias('node/' . $node->nid, isset($node->path) ? $node->path : NULL, isset($node->pid) ? $node->pid : NULL, $language); + } +} - case 'delete': - $path = 'node/' . $node->nid; - if (drupal_get_path_alias($path) != $path) { - path_set_alias($path); - } - break; +/** + * Implementation of hook_nodeapi_delete(). + */ +function path_nodeapi_delete(&$node, $arg) { + if (user_access('create url aliases') || user_access('administer url aliases')) { + $language = isset($node->language) ? $node->language : ''; + $path = 'node/' . $node->nid; + if (drupal_get_path_alias($path) != $path) { + path_set_alias($path); } } } |