? .custom_links.admin.inc.swp
? .custom_links.module.swp
Index: custom_links.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/custom_links/custom_links.admin.inc,v
retrieving revision 1.1
diff -u -p -r1.1 custom_links.admin.inc
--- custom_links.admin.inc	27 Jan 2008 09:16:01 -0000	1.1
+++ custom_links.admin.inc	15 Jan 2009 00:43:59 -0000
@@ -12,7 +12,7 @@ function custom_links_page() {
     $row = array();
     $row[] = $link->link_key;
     $row[] =  $link->title;
-    $row[] =  l(t('edit'), 'admin/build/custom_links/edit/' . $link->lid);
+    $row[] =  l(t('edit'), 'admin/build/custom_links/' . $link->lid . '/edit') . ' ' . l(t('delete'), 'admin/build/custom_links/' . $link->lid . '/delete');
     $rows[] = $row;
   }
   if (count($rows) == 0) {
@@ -27,17 +27,15 @@ function custom_links_page() {
 
 
 // Displays an edit form for a custom link record.
-function custom_links_form() {
+function custom_links_form(&$form_state, $link = NULL) {
   global $base_url;
 
-  $lid = arg(4);
-  if (isset($lid)) {
-    $link = _custom_links_load_link($lid);
-    $form['lid'] = array(
-      '#type' => 'hidden',
-      '#value' => $lid,
-    );
-  }
+  $lid = empty($link->lid) ? NULL : $link->lid;
+
+  $form['lid'] = array(
+    '#type' => 'value',
+    '#value' => $lid,
+  );
 
   $form['link'] = array(
     '#type' => 'fieldset',
@@ -158,7 +156,7 @@ function custom_links_form() {
     $form['buttons']['delete'] = array(
       '#type' => 'submit',
       '#value' => t('Delete'),
-      '#submit' => array('custom_links_form_delete'),
+      '#submit' => array('custom_links_form_delete_submit'),
     );
   }
 
@@ -182,7 +180,43 @@ function custom_links_form_submit($form,
   $form_state['redirect'] = 'admin/build/custom_links';
 }
 
-function custom_links_form_delete($form, &$form_state) {
-  _custom_links_delete_link($form_state['values']['lid']);
+/**
+ * Button sumit function: handle the 'Delete' button on the node form.
+ */
+function custom_links_form_delete_submit($form, &$form_state) {
+  $destination = '';
+  if (isset($_REQUEST['destination'])) {
+    $destination = drupal_get_destination();
+    unset($_REQUEST['destination']);
+  }
+  $form_state['redirect'] = array('admin/build/custom_links/'. $form_state['values']['lid'] .'/delete', $destination);
+}
+
+/**
+ * Menu callback -- ask for confirmation of link deletion
+ */
+function custom_links_delete_form(&$form_state, $link) {
+  $form['lid'] = array(
+    '#type' => 'value',
+    '#value' => $link->lid,
+  );
+
+  return confirm_form($form,
+    t('Are you sure you want to delete %title?', array('%title' => $link->title)),
+    isset($_GET['destination']) ? $_GET['destination'] : 'admin/build/custom_links/',
+    t('This action cannot be undone.'),
+    t('Delete'),
+    t('Cancel')
+  );
+}
+
+/**
+ * Execute custom link deletion.
+ */
+function custom_links_delete_form_submit($form, &$form_state) {
+  if ($form_state['values']['confirm']) {
+    _custom_links_delete_link($form_state['values']['lid']);
+  }
+
   $form_state['redirect'] = 'admin/build/custom_links';
 }
Index: custom_links.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/custom_links/custom_links.module,v
retrieving revision 1.5
diff -u -p -r1.5 custom_links.module
--- custom_links.module	27 Jan 2008 09:16:01 -0000	1.5
+++ custom_links.module	15 Jan 2009 00:43:59 -0000
@@ -11,27 +11,38 @@ function custom_links_menu() {
     'title' => 'Custom links',
     'description' => 'Add custom links to specific content types.',
     'page callback' => 'custom_links_page',
-    'access callback' => 'user_access',
     'access arguments' => array('administer custom links'),
     'file' => 'custom_links.admin.inc',
   );
-
+  $items['admin/build/custom_links/list'] = array(
+    'title' => 'List',
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+    'page callback' => 'custom_links_page',
+    'access arguments' => array('administer custom links'),
+    'file' => 'custom_links.admin.inc',
+    'weight' => -10,
+  );
   $items['admin/build/custom_links/add'] = array(
-    'title' => 'Add custom breadcrumb',
-    'type' => MENU_CALLBACK,
+    'title' => 'Add',
+    'type' => MENU_LOCAL_TASK,
     'page callback' => 'drupal_get_form',
     'page arguments' => array('custom_links_form'),
-    'access callback' => 'user_access',
     'access arguments' => array('administer custom links'),
     'file' => 'custom_links.admin.inc',
   );
-
-  $items['admin/build/custom_links/edit'] = array(
-    'title' => 'Edit custom breadcrumb',
+  $items['admin/build/custom_links/%custom_links_link/edit'] = array(
+    'title' => 'Edit custom link',
     'type' => MENU_CALLBACK,
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('custom_links_form'),
-    'access callback' => 'user_access',
+    'page arguments' => array('custom_links_form', 3),
+    'access arguments' => array('administer custom links'),
+    'file' => 'custom_links.admin.inc',
+  );
+  $items['admin/build/custom_links/%custom_links_link/delete'] = array(
+    'title' => 'Delete custom link',
+    'type' => MENU_CALLBACK,
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('custom_links_delete_form', 3),
     'access arguments' => array('administer custom links'),
     'file' => 'custom_links.admin.inc',
   );
@@ -122,11 +133,12 @@ function _custom_links_build_links($node
   return $links;
 }
 
-function _custom_links_load_link($lid) {
+/**
+ * Menu wildcard loader.
+ */
+function custom_links_link_load($lid) {
   $sql = 'SELECT * FROM {custom_link} WHERE lid = %d';
-  $result = db_query($sql, $lid);
-  $link = db_fetch_object($result);
-  return $link;
+  return db_fetch_object(db_query($sql, $lid));
 }
 
 function _custom_links_load_all_links($refresh = FALSE) {
