Index: modules/links/links_related.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/links/links_related.module,v
retrieving revision 1.5
diff -u -r1.5 links_related.module
--- modules/links/links_related.module	25 Nov 2005 23:03:46 -0000	1.5
+++ modules/links/links_related.module	10 Sep 2005 00:17:27 -0000
@@ -170,21 +170,6 @@
 function links_related_nodeapi(&$node, $op, $teaser=NULL, $page=NULL) {
 //print("nodeapi $op $node->nid<br>\n");
   switch($op) {
-
-    // This puts a settings checkbox on the default workflow settings
-    // page for all node types (URL=admin/node/configure/defaults).
-    case 'settings':
-      $settings = array();
-      $settings['links_related_types_'.$node->type] = array(
-        '#type' => 'checkbox',
-        '#title' => t('Allow related link URLs'),
-        '#return_value' => 1,
-        '#default_value' => variable_get('links_related_types_'.$node->type, 0),
-        '#description' => t('This setting enables or disables the links_related module for this content type.'),
-      );
-      return $settings;
-      break;
-
     // Load the values of the special table from the database as needed
     case 'load':
       if (variable_get('links_related_types_'. $node->type, FALSE) && ! is_array($_POST['edit']['links_links'])) {
@@ -226,7 +211,7 @@
     // This allows the users to enter the links_related into appropriate
     // node types' edit screens.
     case 'form':
-      if (variable_get('links_related_types_'. $node->type, FALSE)) {
+      if (variable_get('links_related_types_'.$node->type, 0)) {
         _links_related_sort_links($node);
         _links_related_sort_post_links();
         $links =& $node->links_links;
@@ -239,12 +224,10 @@
           '#description' => t('Links are stored as part of the %page. Monitoring and dead link detection are centrally managed from there. <strong>To remove a link from this article, just blank out its URL field or check the Delete box.</strong> If you blank out the title but leave the URL, then the system will suggest a title for you. The Weight allows you to determine the order in which links are displayed; lower numbers float to the top.',array('%page'=>l(t('links management feature'),'admin/links'))),
           '#collapsible' => TRUE,
           '#collapsed' => (count($links) == 0),
+          '#weight' => -16,
         );
-
-        $form['links_links']['open_table'] = array(
-          '#type' => 'markup',
-          '#value' => '<table class="links_related_table" border="1"><tr><th class="links_related_table_url">URL</th><th class="links_related_table_title">Title</th><th class="links_related_table_weight">Weight</th><th class="links_related_table_delete">Delete</th></tr>',
-        );
+        
+        $form['links_links']['#theme'] = 'links_related_form';
 
         // Existing links first
         for ($i=0; $i<count($links); $i++) {
@@ -252,11 +235,6 @@
         }
         $form['links_links'][count($links)] = _links_related_form_line(count($links), NULL);
 
-        $form['links_links']['close_table'] = array(
-          '#type' => 'markup',
-          '#value' => '</table>',
-        );
-
         return $form;
       }
       break;
@@ -274,6 +252,35 @@
   }
 }
 
+function links_related_form_alter($form_id, &$form) {
+  if (isset($form['type']) && $form['type']['#value'] .'_node_settings' == $form_id) {
+    $form['links_related_types_'.$form['type']['#value']] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Allow related link URLs'),
+      '#return_value' => 1,
+      '#default_value' => variable_get('links_related_types_'.$node->type, 0),
+      '#description' => t('This setting enables or disables the links_related module for this content type.'),
+    );
+  }
+}
+
+
+function theme_links_related_form(&$form) {
+  $header = array(t('URL'), t('Title'), t('Weight'), t('Delete'));
+
+  foreach (element_children($form) as $key) {
+    $row = array();
+    $row[] = form_render($form[$key]['url']);
+    $row[] = form_render($form[$key]['link_title']);
+    $row[] = form_render($form[$key]['weight']);
+    $row[] = form_render($form[$key]['delete']);
+    $rows[] = $row;
+  }
+  $output = theme('table', $header, $rows);
+  $output .= form_render($form);
+  return $output;
+}
+
 function __SAVE__links_related_nodeapi(&$node, $op, $teaser=NULL, $page=NULL) {
 //print("links_related_nodeapi() called with op $op\n");
   switch($op) {
@@ -398,51 +405,32 @@
   if (! is_array($link)) {
     $link = array();
   }
-//print('<p>LINK:<br>');
-//var_dump($link);
 
   $entry = array();
 
-  $entry['open_row'] = array(
-    '#type' => 'markup',
-    '#value' => '<tr>',
-  );
 
   $entry['url'] = array(
     '#type' => 'textfield',
     '#default_value' => $link['url'],
-    '#prefix' => '<td class="links_related_table_url">',
-    '#suffix' => '</td>',
   );
 
   $entry['link_title'] = array(
     '#type' => 'textfield',
     '#default_value' => $link['link_title'],
-    '#prefix' => '<td class="links_related_table_link_title">',
-    '#suffix' => '</td>',
   );
 
   $entry['weight'] = array(
     '#type' => 'weight',
     '#default_value' => $link['weight'],
     '#delta' => 5,
-    '#prefix' => '<td class="links_related_table_weight">',
-    '#suffix' => '</td>',
   );
 
   $entry['delete'] = array(
     '#type' => 'checkbox',
     '#return_value' => 1,
     '#default_value' => $link['delete'],
-    '#prefix' => '<td class="links_related_table_delete">',
-    '#suffix' => '</td>',
   ); 
 
-  $entry['close_row'] = array(
-    '#type' => 'markup',
-    '#value' => '</tr>',
-  );
-
   return $entry;
 }
 
@@ -650,4 +638,3 @@
   return form_group(t('Embedded Links'), $html, '<p>' . t('These are the links found inside the page content. You can choose to replace the direct URLs with managed links from the site\'s links catalog (adding new links if necessary), or to replace existing catalog links with the actual direct URLs. Titles added or changed here do not override titles for the same link if it appears on other pages.'));
 }
 
-?>
