function salesforce_mapping_property_validation in Salesforce Suite 7.3
Property field validation callback.
@TODO: Add length validation.
1 string reference to 'salesforce_mapping_property_validation'
- salesforce_mapping_salesforce_mapping_fieldmap_type in modules/
salesforce_mapping/ includes/ salesforce_mapping.fieldmap_type.inc - Implements hook_salesforce_mapping_fieldmap_type().
File
- modules/
salesforce_mapping/ includes/ salesforce_mapping.fieldmap_type.inc, line 413 - Data and callbacks for fieldmap types.
Code
function salesforce_mapping_property_validation($drupal_field, $sf_field, $direction, $key) {
$valid = FALSE;
$length_valid = TRUE;
// Type validation
// direction[array Salesforce type][array Drupal type]
$verify_array = array(
'sync' => array(
'string' => array(
'text',
'list<text>',
'uri',
),
'int' => array(
'integer',
),
'id' => array(
'text',
),
'datetime' => array(
'date',
),
'email' => array(
'text',
),
),
'drupal_sf' => array(
// Allow any source field for string type.
'string' => array(),
'int' => array(
'integer',
),
'id' => array(
'text',
),
'datetime' => array(
'date',
),
'email' => array(
'text',
),
),
'sf_drupal' => array(
'string' => array(
'text',
'int',
'list<text>',
),
'int' => array(
'integer',
),
'id' => array(
'text',
),
'datetime' => array(
'date',
),
'email' => array(
'text',
),
),
);
$drupal_type = isset($drupal_field['type']) ? $drupal_field['type'] : 'text';
$sf_type_array = isset($verify_array[$direction][$sf_field['type']]) ? $verify_array[$direction][$sf_field['type']] : array();
if (empty($sf_type_array)) {
// If type is not found in validation array, assume valid.
return TRUE;
}
$type_valid = array_search($drupal_type, $sf_type_array) === FALSE ? FALSE : TRUE;
$valid = $type_valid && $length_valid;
if (!$valid) {
form_set_error("salesforce_field_mappings][{$key}][salesforce_field", t('Drupal field %drupal_label is of type %drupal_type, Salesforce field %sf_label is of type %sf_type and cannot be mapped in the %dir direction', array(
'%drupal_label' => $drupal_field['label'],
'%drupal_type' => $drupal_type,
'%sf_label' => $sf_field['label'],
'%sf_type' => $sf_field['type'],
'%dir' => $direction,
)));
}
// Ensure that a property has a setter method if it needs to be updated.
if (in_array($direction, array(
SALESFORCE_MAPPING_DIRECTION_SYNC,
SALESFORCE_MAPPING_DIRECTION_SF_DRUPAL,
))) {
if (empty($drupal_field['setter callback'])) {
form_set_error("salesforce_field_mappings][{$key}][salesforce_field", t('Drupal field %drupal_label does not have a setter method and cannot be written to.', array(
'%drupal_label' => $drupal_field['label'],
)));
}
}
}