summaryrefslogtreecommitdiff
path: root/modules/path
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-08-15 15:45:07 +0000
committerDries Buytaert <dries@buytaert.net>2009-08-15 15:45:07 +0000
commitbf8e86f7895fd9ca633299cefddd08f029f8274d (patch)
tree3ac7d8ad05aaea8bdb1e7e05845d9ef8a25fd179 /modules/path
parent5ff1f14447ead6a55da88fe8116ab38e21623c7e (diff)
downloadbrdo-bf8e86f7895fd9ca633299cefddd08f029f8274d.tar.gz
brdo-bf8e86f7895fd9ca633299cefddd08f029f8274d.tar.bz2
- Patch #476290 by tylor, evlis2, bohjan, Psicomante et al: add path alias to taxonomy term edit page. Yay.
Diffstat (limited to 'modules/path')
-rw-r--r--modules/path/path.module78
1 files changed, 78 insertions, 0 deletions
diff --git a/modules/path/path.module b/modules/path/path.module
index 12530916d..76a9332c4 100644
--- a/modules/path/path.module
+++ b/modules/path/path.module
@@ -210,6 +210,13 @@ function path_node_update($node) {
function path_node_delete($node) {
path_set_alias('node/' . $node->nid);
}
+
+/**
+ * Implement hook_taxonomy_term_delete().
+ */
+function path_taxonomy_term_delete($term) {
+ path_set_alias('taxonomy/term/' . $term->tid);
+}
/**
* Implement hook_form_alter().
@@ -250,6 +257,77 @@ function path_form_alter(&$form, $form_state, $form_id) {
}
/**
+ * Implement hook_form_FORM_ID_alter().
+ */
+function path_form_taxonomy_form_term_alter(&$form, $form_state) {
+ // Make sure this does not show up on the delete confirmation form.
+ if (empty($form_state['confirm_delete'])) {
+ // After a new term is added, populate the path field if it was set.
+ if (!empty($form['#term']['path'])) {
+ $path = $form['#term']['path'];
+ }
+ else {
+ $url = 'taxonomy/term/' . $form['#term']['tid'];
+ $alias = drupal_get_path_alias($url);
+
+ // Since drupal_get_path_alias() can return the default path, check if we really have an alias.
+ if ($alias != $url) {
+ $path = $alias;
+ }
+ else {
+ $path = NULL;
+ }
+ }
+ $form['#validate'][] = 'path_taxonomy_term_validate';
+ $form['#submit'][] = 'path_taxonomy_term_submit';
+ $form['identification']['path'] = array(
+ '#type' => 'textfield',
+ '#title' => t('URL alias'),
+ '#default_value' => $path,
+ '#maxlength' => 255,
+ '#weight' => 0,
+ '#access' => (user_access('create url aliases') || user_access('administer url aliases')),
+ '#description' => t("Optionally specify an alternative URL by which this term can be accessed. Use a relative path and don't add a trailing slash or the URL alias won't work."),
+ );
+ if ($path) {
+ // Populate with pid so we can update existing path entry instead of creating a new one.
+ $form['identification']['path']['pid'] = array(
+ '#type' => 'value',
+ '#access' => (user_access('create url aliases') || user_access('administer url aliases')),
+ '#value' => db_query("SELECT pid FROM {url_alias} WHERE dst = :dst", array(':dst' => $path))->fetchField(),
+ );
+ }
+ }
+}
+
+/**
+ * Path validation callback for taxonomy_form_term.
+ */
+function path_taxonomy_term_validate($form, &$form_state) {
+ $pid = db_query("SELECT pid FROM {url_alias} WHERE dst = :dst", array(':dst' => $form_state['values']['path']))->fetchField();
+ if ($pid) {
+ // If the pid matches the one in use for this term then we are fine.
+ if (isset($form_state['values']['pid']) && $pid == $form_state['values']['pid']) {
+ return;
+ }
+ form_set_error('path', 'The URL alias is already in use.');
+ }
+}
+
+/**
+ * Path submission callback for taxonomy_form_term.
+ */
+function path_taxonomy_term_submit($form, &$form_state) {
+ // Make sure this is not triggered on the delete confirmation form.
+ if (empty($form_state['confirm_delete'])) {
+ $url = 'taxonomy/term/' . $form_state['tid'];
+ $alias = isset($form_state['values']['path']) ? $form_state['values']['path'] : NULL;
+ $pid = isset($form_state['values']['pid']) ? $form_state['values']['pid'] : NULL;
+ path_set_alias($url, $alias, $pid);
+ }
+}
+
+/**
* Implement hook_permission().
*/
function path_permission() {