function _sf_entity_import_process_entity in Salesforce Suite 7.2
Helper function to populate necessary values after the import data is received, and do matching necessary to prevent duplicate entry errors. Includes a hook to add additional properties to the entity.
Parameters
object $entity: The entity object, passed by reference so it can be modified by this function.
string $entity_type: The entity type for the entity being created.
string $bundle_name: Name of the bundle for the given entity. (Optional)
Return value
void
1 call to _sf_entity_import_process_entity()
- sf_entity_import in sf_entity/
sf_entity.module - Imports data from Salesforce into a Drupal entity
File
- sf_entity/
sf_entity.module, line 1204 - Integrates fieldable entities with the Salesforce API.
Code
function _sf_entity_import_process_entity(&$entity, $entity_type, $bundle_name = NULL) {
if ($entity_type == 'user') {
// Status property must be set.
if (!property_exists($entity, 'status')) {
$entity->status = 1;
}
// If the created date is still empty, set it to now.
if (!isset($entity->created) || empty($entity->created)) {
$entity->created = REQUEST_TIME;
}
// If there is no password set, then generate a random password.
if (!isset($entity->pass) || empty($entity->pass)) {
$entity->pass = drupal_hash_base64(drupal_random_bytes(55));
}
// Look for an existing user if there is a username set.
// @todo: Instead of using $conditions here, fix sf_prematch.module
// to use EntityFieldQuery as per #1214100.
if (isset($entity->name)) {
$existing_user = entity_load('user', FALSE, array(
'name' => $entity->name,
));
}
if (is_array($existing_user)) {
$existing_user = current($existing_user);
}
// If there is an existing user, then set the uid for an update, and unset the is_new flag.
if (isset($existing_user) && is_object($existing_user) && isset($existing_user->uid)) {
$entity->uid = $existing_user->uid;
$entity->roles = $existing_user->roles;
unset($entity->is_new);
}
}
// If language has not yet been set for a node, set it to unknown.
if ($entity_type == 'node') {
if (!isset($entity->language) || empty($entity->language)) {
$entity->language = LANGUAGE_NONE;
}
if (!isset($entity->created) || empty($entity->created)) {
$entity->created = REQUEST_TIME;
}
}
// Ensure that all taxonomy terms have an input format set.
// Use plain_text as the default, since it should always exist.
if ($entity_type == 'taxonomy_term') {
if (!isset($entity->format) || empty($entity->format)) {
$entity->format = 'plain_text';
}
}
// Invoke a hook to process the entity further as needed.
// We cannot use module_invoke_all() since the entity needs to be passed by reference.
foreach (module_implements('salesforce_api_process_entity') as $module) {
$function = $module . '_salesforce_api_process_entity';
$function($entity, $entity_type, $bundle_name);
}
}