? 547260-15-salesforce_fieldmap_fixed_or_php_values.patch
Index: salesforce_api/salesforce_api.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/salesforce/salesforce_api/salesforce_api.admin.inc,v
retrieving revision 1.2.2.36
diff -u -p -r1.2.2.36 salesforce_api.admin.inc
--- salesforce_api/salesforce_api.admin.inc	11 Nov 2010 20:29:48 -0000	1.2.2.36
+++ salesforce_api/salesforce_api.admin.inc	30 Nov 2010 21:40:58 -0000
@@ -422,6 +422,12 @@ function salesforce_api_fieldmap_delete_
  * Displays the edit form for adding field associations to a fieldmap.
  */
 function salesforce_api_fieldmap_edit_form(&$form_state, $fieldmap) {
+  
+  // Include the CSS and JS for the form.
+  $path = drupal_get_path("module", "salesforce_api");
+  drupal_add_css($path .'/misc/salesforce_api.admin.css');
+  drupal_add_js($path ."/misc/salesforce_api.admin.js"); 
+  
   // Load the fieldmap from the database.
   $map = salesforce_api_fieldmap_load($fieldmap);
 
@@ -535,18 +541,43 @@ function salesforce_api_fieldmap_edit_fo
         t('This field will be available for imports only.') . '">' . t('Read-only') . '</span>';
     }
 
-    // Create a row for this field.
     $row = array(
       'target' => array('#value' => $value['label'] . $required),
     );
-
+    
+    // Adding fixed value option
+    $options = salesforce_api_fieldmap_field_options($source);
+    $options['Other']['fixed'] = t('Fixed value');
+    if( user_access('use php for salesforce fixed values') ) {
+      $options['Other']['php'] = t('Evaluate PHP');
+    }
+    if (is_array($map['fields'][$key])) {
+      $default_key = $map->fields[$key]['type'];
+      $default_value = $map->fields[$key]['value'];
+    } else {
+      $default_key = $map->fields[$key];
+      $default_value = null;
+    }
+  
     // Add the select list for the associated target field.
     $row['source'][$key] = array(
       '#type' => 'select',
       '#title' => $value['label'],
-      '#options' => salesforce_api_fieldmap_field_options($source),
-      '#default_value' => $map->fields[$key],
+      '#options' => $options,
+      '#default_value' => $default_key,
       '#required' => $type == 'required',
+      '#attributes' => array('class' => 'sf_fieldmap_options', 'id' => 'sf-fieldmap-option-' . $key),
+      );
+    $row['source'][$key ."_extra"] = array(
+      '#type' => 'textfield',
+      '#title' => t('Value'),
+      '#default_value' => $default_value,
+      '#size' => 20,
+      '#maxlength' => 512,
+      '#required' => FALSE,
+      '#prefix' => '<div id="'. $key .'-extra-hidden" class="fieldmap-extra-text">',
+      '#suffix' => '</div>',
+      '#description' => 'Omit &lt;?php ?&gt; tags. Return the value to set. Standard caveats apply.',
     );
 
     // Add the row to the correct rows array.
@@ -570,9 +601,10 @@ function salesforce_api_fieldmap_edit_fo
  *
  */
 function salesforce_api_fieldmap_edit_form_validate($form, &$form_state) {
-  // Include the CSS file for the form on reload as long as Drupal won't do it for us.
-  $path = drupal_get_path('module', 'salesforce_api');
-  drupal_add_css($path . '/misc/salesforce_api.admin.css');
+  // Include the CSS and JS for the form if it gets reloaded.
+  $path = drupal_get_path("module", "salesforce_api");
+  drupal_add_css($path .'/misc/salesforce_api.admin.css');
+  drupal_add_js($path ."/misc/salesforce_api.admin.js"); 
 }
 
 /**
@@ -590,8 +622,14 @@ function salesforce_api_fieldmap_edit_fo
 
   // Loop through all the fields on the object.
   foreach (array_keys($object['fields']) as $field) {
+    if (!empty($form_state['values'][$field .'_extra'])) {
+      $map['fields'][$field] = array(
+        'type' => $form_state['values'][$field], 
+        'value' => $form_state['values'][$field .'_extra']
+      );
+    }
     // If a field has been mapped to this field on the form...
-    if (!empty($form_state['values'][$field])) {
+    elseif (!empty($form_state['values'][$field])) {
       // Add the association to the fieldmap's fields array.
       $map->fields[$field] = $form_state['values'][$field];
     }
@@ -640,7 +678,7 @@ function theme_salesforce_api_fieldmap_e
 
   foreach (element_children($form['rows']) as $element) {
     $rows[] = array(
-      drupal_render($form['rows'][$element]['target']),
+      array('data' => drupal_render($form['rows'][$element]['target']), 'class' => 'target-cell'),
       array('data' => drupal_render($form['rows'][$element]['source']), 'class' => 'source-cell'),
     );
   }
Index: salesforce_api/salesforce_api.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/salesforce/salesforce_api/salesforce_api.module,v
retrieving revision 1.2.2.52
diff -u -p -r1.2.2.52 salesforce_api.module
--- salesforce_api/salesforce_api.module	11 Nov 2010 22:07:02 -0000	1.2.2.52
+++ salesforce_api/salesforce_api.module	30 Nov 2010 21:40:58 -0000
@@ -219,7 +219,7 @@ function salesforce_api_menu() {
  * Implementation of hook_perm().
  */
 function salesforce_api_perm() {
-  return array('administer salesforce');
+  return array('administer salesforce', 'use php for salesforce fixed values');
 }
 
 /**
@@ -770,8 +770,23 @@ function salesforce_api_fieldmap_export_
     || (!empty($drupal_data->salesforce->sfid) && !$updateable)) {
       continue;
     }
+    // See if it's a special field
+    if (is_array($map->fields[$sf_fieldname]))  {
+      switch ($map->fields[$sf_fieldname]['type']) {
+        case 'fixed':
+          if (isset($map->fields[$sf_fieldname]['value'])) {
+            $object->$sf_fieldname = htmlentities($map->fields[$sf_fieldname]['value']);
+          }
+          break;
+        case 'php':
+          if(isset($map->fields[$sf_fieldname]['value'])) {
+            $object->$sf_fieldname = htmlentities(eval($map->fields[$sf_fieldname]['value']));
+          }
+          break;
+      }
+    }
     // If a handler is specified for retrieving a value for the Drupal field...
-    if (isset($drupal_object_definition['fields'][$drupal_fieldname]['export'])) {
+    elseif (isset($drupal_object_definition['fields'][$drupal_fieldname]['export'])) {
       $drupal_field_export_handler =
         $drupal_object_definition['fields'][$drupal_fieldname]['export'];
       $drupal_field_definition =
Index: sf_prematch/sf_prematch.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/salesforce/sf_prematch/Attic/sf_prematch.admin.inc,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 sf_prematch.admin.inc
--- sf_prematch/sf_prematch.admin.inc	14 Jul 2010 14:52:13 -0000	1.1.2.3
+++ sf_prematch/sf_prematch.admin.inc	30 Nov 2010 21:40:58 -0000
@@ -223,10 +223,16 @@ function sf_prematch_get_options($map, $
   // Build terms into ordered options to use in select.
   $options = array();
   // Start with empty option if select is not required.
-  if (!$required) {$options[] = '';}
+  if (!$required) { $options[] = ''; }
 
   // Add terms to options, making key = value so form value is key not integer.
   foreach ($terms as $term) {
+    if (is_array($term)) {
+      $term = implode(' : ', $term);
+      if (strlen($term) > 50) {
+        $term = substr($term, 0, 50) . ' ...';
+      }
+    }
   	$options[$term] = $term;
   }
 
