? 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	13 Jul 2010 23:20: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	13 Jul 2010 23:20:04 -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,112 @@
 }
 
 /**
+ * Implements hook_field_settings_form().
+ */
+function link_field_settings_form($field, $instance, $has_data) {
+  $form = array(
+    '#theme' => 'link_field_settings',
+  );
+  
+  $form['url'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Optional URL'),
+    '#default_value' => isset($field['url']) ? $field['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['title']) ? $field['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',
+    '#default_value' => isset($field['title_value']) ? $field['title_value'] : '',
+    '#size' => '46',
+  );
+  
+  // 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['enable_tokens']) ? $field['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['display']['url_cutoff']) ? $field['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['attributes']['target']) ? LINK_TARGET_DEFAULT : $field['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['attributes']['rel']) ? '' : $field['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['attributes']['class']) ? '' : $field['attributes']['class'],
+  );
+  return $form;
+}
+
+/**
  * Implementation of hook_field_settings().
  */
+/*
 function link_field_settings($op, $field) {
   switch ($op) {
     case 'form':
@@ -195,6 +299,7 @@
       return link_views_content_field_data($field);
   }
 }
+*/
 
 /**
  * Theme the settings form for the link field.
@@ -211,7 +316,7 @@
 }
 
 /**
- * Implement hook_field_is_empty().
+ * Implements hook_field_is_empty().
  */
 function link_field_is_empty($item, $field) {
   if (empty($item['title']) && empty($item['url'])) {
@@ -221,8 +326,39 @@
 }
 
 /**
+ * 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['url'] == 'optional' && $field['title'] == 'optional' && $field['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);
+  }
+}
+
+/**
  * Implementation of hook_field().
  */
+/*
 function link_field($op, &$node, $field, &$items, $teaser, $page) {
   switch ($op) {
     case 'load':
@@ -252,24 +388,26 @@
       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) {
+function link_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
+/*
   $element = array(
     '#type' => $field['widget']['type'],
     '#default_value' => isset($items[$delta]) ? $items[$delta] : '',
@@ -279,6 +417,7 @@
     '#required' => $field['required'],
     '#field' => $field,
   );
+*/
   return $element;
 }
 
@@ -497,13 +636,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,7 +663,7 @@
  *
  * The $fields array is in $form['#field_info'][$element['#field_name']].
  */
-function link_process($element, $edit, $form_state, $form) {
+function link_field_process($element, $form_state, $form) {
    $field = $form['#field_info'][$element['#field_name']];
    $delta = $element['#delta'];
    $element['url'] = array(
@@ -570,40 +709,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 +775,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 +831,7 @@
   $output .= '</div>';
   return $output;
 }
+*/
 
 function link_token_list($type = 'all') {
   if ($type == 'field' || $type == 'all') {
