Index: salesforce_api/salesforce_api.module =================================================================== --- salesforce_api/salesforce_api.module (revision 900) +++ salesforce_api/salesforce_api.module (revision 905) @@ -219,7 +219,7 @@ * 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 @@ || (!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: salesforce_api/salesforce_api.admin.inc =================================================================== --- salesforce_api/salesforce_api.admin.inc (revision 900) +++ salesforce_api/salesforce_api.admin.inc (revision 905) @@ -422,6 +422,12 @@ * 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 @@ t('This field will be available for imports only.') . '">' . t('Read-only') . ''; } - // 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' => 128, + '#required' => FALSE, + '#prefix' => '
', + '#description' => 'Omit <?php ?> 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_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 @@ // 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 @@ 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: sf_prematch/sf_prematch.admin.inc =================================================================== --- sf_prematch/sf_prematch.admin.inc (revision 900) +++ sf_prematch/sf_prematch.admin.inc (revision 905) @@ -223,10 +223,16 @@ // 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; }