? d7-2.patch
? d7-3.patch
? d7.patch
Index: link.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/link/link.install,v
retrieving revision 1.6
diff -u -r1.6 link.install
--- link.install	9 Nov 2009 06:11:26 -0000	1.6
+++ link.install	15 Jul 2010 08:42:03 -0000
@@ -5,94 +5,3 @@
  * @file
  * Install file for the link module.
  */
-
-/**
- * Implementation of hook_install().
- */
-function link_install() {
-  drupal_load('module', 'content');
-  content_notify('install', 'link');
-}
-
-/**
-* Implementation of hook_uninstall().
-*/
-function link_uninstall() {
-  drupal_load('module', 'content');
-  content_notify('uninstall', 'link');
-}
-
-/**
-* Implementation of hook_enable().
-*/
-function link_enable() {
-  drupal_load('module', 'content');
-  content_notify('enable', 'link');
-}
-
-/**
-* Implementation of hook_disable().
-*/
-function link_disable() {
-  drupal_load('module', 'content');
-  content_notify('disable', 'link');
-}
-
-/**
- * Removed link.module created tables, move data to content.module tables
- *
- * Even though most everyone will not be using this particular update, several
- * folks have complained that their upgrades of link.module do not work because
- * of this function being missing when schema expects it. - JCF
- * And on further review, I'm removing the body, since some of those calls
- * no longer exist in Drupal 6.  Remember to upgrade from 4.7 to 5 first, and
- * *then* from 5 to 6.  kthx! -JCF
- */
-function link_update_1() {
-  $ret = array();
-  // GNDN
-  return $ret;
-}
-
-
-/**
- * Ensure that content.module is updated before link module.
- */
-function link_update_6000() {
-  if ($abort = content_check_update('link')) {
-    return $abort;
-  }
-  return array();
-}
-
-/**
- * Change the database schema to allow NULL values.
- */
-function link_update_6001() {
-  $ret = array();
-  
-  // Build a list of fields that need updating.
-  $update_fields = array();
-  foreach (content_types_install() as $type_name => $fields) {
-    foreach ($fields as $field) {
-      if ($field['type'] == 'link') {
-        // We only process a given field once.
-        $update_fields[$field['field_name']] = $field;
-      }
-    }
-  }
-  
-  // Update each field's storage to match the current definition.
-  foreach ($update_fields as $field) {
-    $db_info = content_database_info($field);
-    foreach ($db_info['columns'] as $column) {
-      db_change_field($ret, $db_info['table'], $column['column'], $column['column'], $column);
-      $ret[] = update_sql("UPDATE {". $db_info['table'] ."} SET ". $column['column'] ." = NULL WHERE ". $column['column'] ." = '' OR ". $column['column'] ." = 'N;'");
-    }
-  }
-  
-  // Let CCK re-associate link fields with Link module and activate the fields.
-  content_associate_fields('link');
-  
-  return $ret;
-}
Index: link.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/link/link.module,v
retrieving revision 1.25.2.1
diff -u -r1.25.2.1 link.module
--- link.module	9 Nov 2009 06:40:50 -0000	1.25.2.1
+++ link.module	15 Jul 2010 08:42:03 -0000
@@ -22,7 +22,7 @@
  */
 function link_field_info() {
   return array(
-    'link' => array(
+    'link_field' => array(
       'label' => t('Link'),
       'description' => t('Store a title, href, and attributes in the database to assemble a link.'),
       'settings' => array(
@@ -71,8 +71,115 @@
 }
 
 /**
+ * Implements hook_field_settings_form().
+ */
+function link_field_settings_form($field, $instance, $has_data) {
+  dsm($field['settings']);
+  $form = array(
+/*     '#theme' => 'link_field_settings', */
+  );
+  
+  $form['url'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Optional URL'),
+    '#default_value' => isset($field['settings']['url']) ? $field['settings']['url'] : '',
+    '#return_value' => 'optional',
+    '#description' => t('If checked, the URL field is optional and submitting a title alone will be acceptable. If the URL is omitted, the title will be displayed as plain text.'),
+  );
+  
+  $title_options = array(
+    'optional' => t('Optional Title'),
+    'required' => t('Required Title'),
+    'value' => t('Static Title'),
+    'none' => t('No Title'),
+  );
+  
+  $form['title'] = array(
+    '#type' => 'radios',
+    '#title' => t('Link Title'),
+    '#default_value' => isset($field['settings']['title']) ? $field['settings']['title'] : 'optional',
+    '#options' => $title_options,
+    '#description' => t('If the link title is optional or required, a field will be displayed to the end user. If the link title is static, the link will always use the same title. If <a href="http://drupal.org/project/token">token module</a> is installed, the static title value may use any other node field as its value. Static and token-based titles may include most inline XHTML tags such as <em>strong</em>, <em>em</em>, <em>img</em>, <em>span</em>, etc.'),
+  );
+  
+  $form['title_value'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Static title'),
+    '#default_value' => isset($field['settings']['title_value']) ? $field['settings']['title_value'] : '',
+/*     '#size' => '46', */
+    '#description' => t('This title will always be used if &ldquo;Static Title&rdquo; is selected above.'),
+  );
+  
+  // Add token module replacements if available
+  if (module_exists('token')) {
+    $form['tokens'] = array(
+      '#type' => 'fieldset',
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+      '#title' => t('Placeholder tokens'),
+      '#description' => t("The following placeholder tokens can be used in both paths and titles. When used in a path or title, they will be replaced with the appropriate values."),
+    );
+    $form['tokens']['help'] = array(
+      '#value' => theme('token_help', 'node'),
+    );
+  
+    $form['enable_tokens'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Allow user-entered tokens'),
+      '#default_value' => isset($field['settings']['enable_tokens']) ? $field['settings']['enable_tokens'] : 1,
+      '#description' => t('Checking will allow users to enter tokens in URLs and Titles on the node edit form. This does not affect the field settings on this page.'),
+    );
+  }
+  
+  $form['display'] = array(
+    '#tree' => TRUE,
+  );
+  $form['display']['url_cutoff'] = array(
+    '#type' => 'textfield',
+    '#title' => t('URL Display Cutoff'),
+    '#default_value' => isset($field['settings']['display']['url_cutoff']) ? $field['settings']['display']['url_cutoff'] : '80',
+    '#description' => t('If the user does not include a title for this link, the URL will be used as the title. When should the link title be trimmed and finished with an elipsis (&hellip;)? Leave blank for no limit.'),
+    '#maxlength' => 3,
+    '#size' => 3,
+  );
+  
+  $target_options = array(
+    LINK_TARGET_DEFAULT => t('Default (no target attribute)'),
+    LINK_TARGET_TOP => t('Open link in window root'),
+    LINK_TARGET_NEW_WINDOW => t('Open link in new window'),
+    LINK_TARGET_USER => t('Allow the user to choose'),
+  );
+  $form['attributes'] = array(
+    '#tree' => TRUE,
+  );
+  $form['attributes']['target'] = array(
+    '#type' => 'radios',
+    '#title' => t('Link Target'),
+    '#default_value' => empty($field['settings']['attributes']['target']) ? LINK_TARGET_DEFAULT : $field['settings']['attributes']['target'],
+    '#options' => $target_options,
+  );
+  $form['attributes']['rel'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Rel Attribute'),
+    '#description' => t('When output, this link will have this rel attribute. The most common usage is <a href="http://en.wikipedia.org/wiki/Nofollow">rel=&quot;nofollow&quot;</a> which prevents some search engines from spidering entered links.'),
+    '#default_value' => empty($field['settings']['attributes']['rel']) ? '' : $field['settings']['attributes']['rel'],
+    '#field_prefix' => 'rel = "',
+    '#field_suffix' => '"',
+    '#size' => 20,
+  );
+  $form['attributes']['class'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Additional CSS Class'),
+    '#description' => t('When output, this link will have have this class attribute. Multiple classes should be separated by spaces.'),
+    '#default_value' => empty($field['settings']['attributes']['class']) ? '' : $field['settings']['attributes']['class'],
+  );
+  return $form;
+}
+
+/**
  * Implementation of hook_field_settings().
  */
+/*
 function link_field_settings($op, $field) {
   switch ($op) {
     case 'form':
@@ -195,34 +302,70 @@
       return link_views_content_field_data($field);
   }
 }
+*/
 
 /**
  * Theme the settings form for the link field.
  */
-function theme_link_field_settings($form) {
-  $title_value = drupal_render($form['title_value']);
-  $title_checkbox = drupal_render($form['title']['value']);
+/*
+function theme_link_field_settings($variables) {
+  $title_value = drupal_render($variables['form']['title_value']);
+  $title_checkbox = drupal_render($variables['form']['title']['value']);
 
   // Set Static Title radio option to include the title_value textfield.
-  $form['title']['value'] = array('#value' => '<div class="container-inline">'. $title_checkbox . $title_value .'</div>');
+  $variables['form']['title']['value']['#title'] = '<div class="container-inline">'. $title_checkbox . $title_value .'</div>';
+  unset($variables['form']['title']['value']['#printed']);
+  unset($variables['form']['title']['value']['#children']);
+
 
   // Reprint the title radio options with the included textfield.
-  return drupal_render($form);
+  unset($variables['form']['#theme']);
+  dsm($variables['form']);
+  return drupal_render($variables['form']);
 }
+*/
 
 /**
- * Implement hook_field_is_empty().
+ * Implements hook_field_is_empty().
  */
 function link_field_is_empty($item, $field) {
-  if (empty($item['title']) && empty($item['url'])) {
-    return TRUE;
+  return empty($item['title']) && empty($item['url']);
+}
+
+/**
+ * Implements hook_field_load().
+ */
+function link_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) {
+  return _link_load($field, $items);
+}
+
+/**
+ * Implements hook_field_validate().
+ */
+function link_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
+  $optional_field_found = FALSE;
+  foreach ($items as $delta => $value) {
+    _link_validate($items[$delta], $delta, $field, $entity, $optional_field_found);
+  }
+
+  if ($field['settings']['url'] === 'optional' && $field['settings']['title'] === 'optional' && $field['settings']['title'] === 'required' && !$optional_field_found) {
+    form_set_error($field['field_name'] .'][0][title', t('At least one title or URL must be entered.'));
+  }
+}
+
+/**
+ * Implements hook_field_presave().
+ */
+function link_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
+  foreach ($items as $delta => $value) {
+    _link_process($items[$delta], $delta, $field, $node);
   }
-  return FALSE;
 }
 
 /**
  * Implementation of hook_field().
  */
+/*
 function link_field($op, &$node, $field, &$items, $teaser, $page) {
   switch ($op) {
     case 'load':
@@ -252,32 +395,28 @@
       break;
   }
 }
+*/
 
 /**
- * Implementation of hook_widget_info().
+ * Implements hook_field_widget_info().
  */
-function link_widget_info() {
+function link_field_widget_info() {
   return array(
-    'link' => array(
+    'link_field' => array(
       'label' => 'Link',
-      'field types' => array('link'),
-      'multiple values' => CONTENT_HANDLE_CORE,
+      'field types' => array('link_field'),
+      'multiple values' => FIELD_BEHAVIOR_DEFAULT,
     ),
   );
 }
 
 /**
- * Implementation of hook_widget().
+ * Implements hook_field_widget_form().
  */
-function link_widget(&$form, &$form_state, $field, $items, $delta = 0) {
-  $element = array(
-    '#type' => $field['widget']['type'],
+function link_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
+  $element += array(
+    '#type' => $instance['widget']['type'],
     '#default_value' => isset($items[$delta]) ? $items[$delta] : '',
-    '#title' => $field['widget']['label'],
-    '#weight' => $field['widget']['weight'],
-    '#description' => $field['widget']['description'],
-    '#required' => $field['required'],
-    '#field' => $field,
   );
   return $element;
 }
@@ -437,31 +576,34 @@
 /**
  * Implementation of hook_theme().
  */
-function link_theme() {
+function link_theme($existing, $type, $theme, $path) {
   return array(
+/*
     'link_field_settings' => array(
-      'arguments' => array('element' => NULL),
+      // 'variables' => array('form' => NULL),
+      'render element' => 'form',
     ),
+*/
     'link_formatter_default' => array(
-      'arguments' => array('element' => NULL),
+      'variables' => array('element' => NULL),
     ),
     'link_formatter_plain' => array(
-      'arguments' => array('element' => NULL),
+      'variables' => array('element' => NULL),
     ),
     'link_formatter_url' => array(
-      'arguments' => array('element' => NULL),
+      'variables' => array('element' => NULL),
     ),
     'link_formatter_short' => array(
-      'arguments' => array('element' => NULL),
+      'variables' => array('element' => NULL),
     ),
     'link_formatter_label' => array(
-      'arguments' => array('element' => NULL),
+      'variables' => array('element' => NULL),
     ),
     'link_formatter_separate' => array(
-      'arguments' => array('element' => NULL),
+      'variables' => array('element' => NULL),
     ),
     'link' => array(
-      'arguments' => array('element' => NULL),
+      'variables' => array('element' => NULL),
     ),
   );
 }
@@ -497,13 +639,13 @@
 }
 
 /**
- * Implementation of hook_elements().
+ * Implements hook_element_info().
  */
-function link_elements() {
+function link_element_info() {
   $elements = array();
-  $elements['link'] =  array(
+  $elements['link_field'] =  array(
     '#input' => TRUE,
-    '#process' => array('link_process'),
+    '#process' => array('link_field_process'),
   );
   return $elements;
 }
@@ -524,43 +666,49 @@
  *
  * The $fields array is in $form['#field_info'][$element['#field_name']].
  */
-function link_process($element, $edit, $form_state, $form) {
-   $field = $form['#field_info'][$element['#field_name']];
-   $delta = $element['#delta'];
-   $element['url'] = array(
+function link_field_process($element, $form_state, $form) {
+  $settings = &$form_state['field'][$element['#field_name']][$element['#language']]['field']['settings'];
+/*   dsm($element); */
+/*
+  dsm($form);
+  dsm($form_state);
+*/
+/*   $field = $form[$element['#field_name']]; */
+/*   $delta = $element['#delta']; */
+  $element['url'] = array(
+   '#type' => 'textfield',
+   '#maxlength' => '255',
+   '#title' => t('URL'),
+   '#description' => $element['#description'],
+   '#required' => ($element['#delta'] == 0 && $settings['url'] !== 'optional') ? $element['#required'] : FALSE,
+   '#default_value' => isset($element['#value']['url']) ? $element['#value']['url'] : NULL,
+  );
+  if ($settings['title'] !== 'none' && $settings['title'] !== 'value') {
+   $element['title'] = array(
      '#type' => 'textfield',
      '#maxlength' => '255',
-     '#title' => t('URL'),
-     '#description' => $element['#description'],
-     '#required' => ($delta == 0 && $field['url'] !== 'optional') ? $element['#required'] : FALSE,
-     '#default_value' => isset($element['#value']['url']) ? $element['#value']['url'] : NULL,
+     '#title' => t('Title'),
+     '#required' => ($element['#delta'] == 0 && $field['title'] === 'required') ? $field['required'] : FALSE,
+     '#default_value' => isset($element['#value']['title']) ? $element['#value']['title'] : NULL,
+   );
+  }
+  
+  // Initialize field attributes as an array if it is not an array yet.
+  if (!is_array($settings['attributes'])) {
+   $settings['attributes'] = array();
+  }
+  // Add default atrributes.
+  $settings['attributes'] += _link_default_attributes();
+  $attributes = isset($element['#value']['attributes']) ? $element['#value']['attributes'] : $settings['attributes'];
+  if (!empty($settings['attributes']['target']) && $settings['attributes']['target'] == LINK_TARGET_USER) {
+   $element['attributes']['target'] = array(
+     '#type' => 'checkbox',
+     '#title' => t('Open URL in a New Window'),
+     '#return_value' => LINK_TARGET_NEW_WINDOW,
+     '#default_value' => $attributes['target'],
    );
-   if ($field['title'] != 'none' && $field['title'] != 'value') {
-     $element['title'] = array(
-       '#type' => 'textfield',
-       '#maxlength' => '255',
-       '#title' => t('Title'),
-       '#required' => ($delta == 0 && $field['title'] == 'required') ? $field['required'] : FALSE,
-       '#default_value' => isset($element['#value']['title']) ? $element['#value']['title'] : NULL,
-     );
-   }
-
-   // Initialize field attributes as an array if it is not an array yet.
-   if (!is_array($field['attributes'])) {
-     $field['attributes'] = array();
-   }
-   // Add default atrributes.
-   $field['attributes'] += _link_default_attributes();
-   $attributes = isset($element['#value']['attributes']) ? $element['#value']['attributes'] : $field['attributes'];
-   if (!empty($field['attributes']['target']) && $field['attributes']['target'] == LINK_TARGET_USER) {
-     $element['attributes']['target'] = array(
-       '#type' => 'checkbox',
-       '#title' => t('Open URL in a New Window'),
-       '#return_value' => LINK_TARGET_NEW_WINDOW,
-       '#default_value' => $attributes['target'],
-     );
-   }
-   return $element;
+  }
+  return $element;
 }
 
 /**
@@ -570,40 +718,61 @@
   return array(
     'default' => array(
       'label' => t('Title, as link (default)'),
-      'field types' => array('link'),
-      'multiple values' => CONTENT_HANDLE_CORE,
+      'field types' => array('link_field'),
+      'multiple values' => FIELD_BEHAVIOR_DEFAULT,
     ),
     'url' => array(
       'label' => t('URL, as link'),
-      'field types' => array('link'),
-      'multiple values' => CONTENT_HANDLE_CORE,
+      'field types' => array('link_field'),
+      'multiple values' => FIELD_BEHAVIOR_DEFAULT,
     ),
     'plain' => array(
       'label' => t('URL, as plain text'),
-      'field types' => array('link'),
-      'multiple values' => CONTENT_HANDLE_CORE,
+      'field types' => array('link_field'),
+      'multiple values' => FIELD_BEHAVIOR_DEFAULT,
     ),
     'short' => array(
       'label' => t('Short, as link with title "Link"'),
-      'field types' => array('link'),
-      'multiple values' => CONTENT_HANDLE_CORE,
+      'field types' => array('link_field'),
+      'multiple values' => FIELD_BEHAVIOR_DEFAULT,
     ),
     'label' => array(
       'label' => t('Label, as link with label as title'),
-      'field types' => array('link'),
-      'multiple values' => CONTENT_HANDLE_CORE,
+      'field types' => array('link_field'),
+      'multiple values' => FIELD_BEHAVIOR_DEFAULT,
     ),
     'separate' => array(
       'label' => t('Separate title and URL'),
-      'field types' => array('link'),
-      'multiple values' => CONTENT_HANDLE_CORE,
+      'field types' => array('link_field'),
+      'multiple values' => FIELD_BEHAVIOR_DEFAULT,
     ),
   );
 }
 
+function link_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
+  $element = array();
+  foreach ($items as $delta => $item) {
+    if (!empty($item['display_title'])) {
+      if (!empty($item['url'])) {
+        $element[$delta] = array(
+          '#markup' => l($item['display_title'], $item['url'], $item),
+        );
+      }
+      else {
+        // If only a title, display the title.
+        $element[$delta] = array(
+          '#markup' => check_plain($item['display_title']),
+        );
+      }
+    }
+  }
+  return $element;
+}
+
 /**
  * Theme function for 'default' text field formatter.
  */
+/*
 function theme_link_formatter_default($element) {
   //drupal_set_message('<pre>'. print_r($element['#item'], TRUE) .'</pre>');
   // Display a normal link if both title and URL are available.
@@ -615,38 +784,48 @@
     return check_plain($element['#item']['display_title']);
   }
 }
+*/
 
 /**
  * Theme function for 'plain' text field formatter.
  */
+/*
 function theme_link_formatter_plain($element) {
   return empty($element['#item']['url']) ? check_plain($element['#item']['title']) : url($element['#item']['url'], $element['#item']);
 }
+*/
 
 /**
  * Theme function for 'url' text field formatter.
  */
+/*
 function theme_link_formatter_url($element) {
   return $element['#item']['url'] ? l($element['#item']['display_url'], $element['#item']['url'], $element['#item']) : '';
 }
+*/
 
 /**
  * Theme function for 'short' text field formatter.
  */
+/*
 function theme_link_formatter_short($element) {
   return $element['#item']['url'] ? l(t('Link'), $element['#item']['url'], $element['#item']) : '';
 }
+*/
 
 /**
  * Theme function for 'label' text field formatter.
  */
+/*
 function theme_link_formatter_label($element) {
   return $element['#item']['url'] ? l($element['#item']['label'], $element['#item']['url'], $element['#item']) : '';
 }
+*/
 
 /**
  * Theme function for 'separate' text field formatter.
  */
+/*
 function theme_link_formatter_separate($element) {
   $class = empty($element['#item']['attributes']['class']) ? '' : ' '. $element['#item']['attributes']['class'];
   unset($element['#item']['attributes']['class']);
@@ -661,6 +840,7 @@
   $output .= '</div>';
   return $output;
 }
+*/
 
 function link_token_list($type = 'all') {
   if ($type == 'field' || $type == 'all') {
