function salesforce_api_import_salesforce_fieldmap_validate in Salesforce Suite 7.2
Validation function for salesforce_api_import_fieldmap(). Makes sure that an import actually provides a handler.
File
- salesforce_api/
salesforce_api.module, line 2192 - Defines an API that enables modules to interact with the Salesforce server.
Code
function salesforce_api_import_salesforce_fieldmap_validate($form, &$form_state) {
// First, run the PHP and turn the input code into an object.
$name = $form_state['values']['name'];
if (preg_match('/[^a-z0-9_]/', $name)) {
form_error($form['name'], t('Invalid name. Please use letters, numbers, or underscores only.'));
}
ob_start();
eval($form_state['values']['object']);
ob_end_clean();
// The object should appear as $salesforce_fieldmap.
// This was the "identifier" set in the export section of the {salesforce_fieldmap} schema.
if (empty($salesforce_fieldmap)) {
$errors = ob_get_contents();
if (empty($errors)) {
$errors = t('Could not load a fieldmap from this input. Check your code for errors.');
}
form_error($form['object'], t('Unable to get a fieldmap from the import. Errors reported: @errors', array(
'@errors' => $errors,
)));
}
if (empty($salesforce_fieldmap->drupal_entity) || empty($salesforce_fieldmap->drupal_bundle) || empty($salesforce_fieldmap->salesforce)) {
form_error($form['object'], t('This fieldmap cannot be imported; the object definition is invalid.'));
return;
}
if (!salesforce_api_fieldmap_source_entity_enabled($salesforce_fieldmap)) {
form_error($form['object'], t('This fieldmap cannot be imported, because the module which supports the Drupal entity "%entity" cannot be found. Please make sure you have required any modules with which this fieldmap was built.', array(
'%entity' => $salesforce_fieldmap->drupal_entity,
)));
}
if (!salesforce_api_fieldmap_source_bundle_enabled($salesforce_fieldmap)) {
form_error($form['object'], t('This fieldmap cannot be imported, because the module which supports the Drupal entity type "%bundle" cannot be found. Please make sure you have required any modules with which this fieldmap was built.', array(
'%entity' => $salesforce_fieldmap->drupal_bundle,
)));
}
// Try to enable the Salesforce object if it was not found.
if (!salesforce_api_fieldmap_target_enabled($salesforce_fieldmap)) {
form_error($form['object'], t('This fieldmap cannot be imported because the Salesforce API module cannot find a definition for the Salesforce object "%sfobj". Please verify your Salesforce connection and settings.', array(
'%sfobj' => $salesforce_fieldmap->salesforce,
)));
}
$form_state['obj'] = $salesforce_fieldmap;
}