Is there a way to map drupal vocabulary terms (the term name and not id) wiith Salesforce fields?
Thanks!

Comments

duit’s picture

Had any luck with this?

coatezy’s picture

Issue summary: View changes

Has anybody managed to achieve this? This is the only thing that I have struggled to do with the module so far, a testament to the guys developing it!

taits’s picture

Also curious if anyone has achieved success with this?

tauno’s picture

Category: Support request » Feature request

For pushing, you might be able to use a token. For pulling, you would need to implement hook_salesforce_pull_entity_value_alter() to use a term name from SF and convert that to a term id in Drupal.

A custom field mapping handler could be implemented to make this all possible from the UI. Moving to the Feature Request queue.

mikechristianson’s picture

I took the first part of tauno's advice and implemented hook_salesforce_pull_entity_value_alter() to successfully map Salesforce Object fields to Drupal Taxonomy terms. I used the Content Type’s mapped field to obtain the Vocabulary and chose to either create a new term or use the existing one.

Please see my post for more detail and the code I used. NB: this solution hijacks the module’s concept of Related Entity; the way I went about it prevents its original, intended usage. I should have used a custom mapping handler and created a proper UI for it.

In the near future I hope to resolve the deficiencies in my implementation and contribute my solution back to this community.

jimafisk’s picture

I've started creating a module based on mikechristianson's work (thank you Mike): https://www.drupal.org/project/salesforce_term_ref

I wanted to add additional controls to allow users to choose whether or not to add new terms to their taxonomies when incoming terms from Salesforce don't match existing terms. I've done a hook_form_ID_alter() on the salesforce_mapping_form and updated the schema for the salesforce_mapping table to allow saving these settings, which could be different for each salesforce_mapping_id.

I'm having trouble retrieving these settings in order to control whether terms are created or not, which I'm attempting to implement around line 168 of salesforce_term_ref.module - in salesforce_term_ref_create_or_load_term(). I can't seem to get the context for the salesforce_mapping_id outside of the form_alter. To get around this, I was passing this information via a $_SESSION variable, which actually seemed to work when running cron manually through the browser (does not work if you run 'drush cron'). Is there a better way to approach this? Thanks!

mariacha1’s picture

If you want to load the values of a given mapping, you should use:

$mapping = entity_load('salesforce_mapping', $my_mapping_id);

If the value isn't in there, it's possible that it isn't being saved to the database.

jimafisk’s picture

Thank you mariacha1! I think something like entity_load is exactly what I need. The trouble I'm having is getting the salesforce_mapping_id where I'm trying to implement the control. All the logic starts from a hook_salesforce_pull_entity_value_alter() and I can't seem to find the ID for the mapper in $value, $field_map, or $sf_object.

jimafisk’s picture

I ended up passing the $sf_object variable by reference to hook_salesforce_pull_mapping_object_alter() in order to modify it to include $mapping->salesforce_mapping_id.

/**
 * Implements hook_salesforce_pull_mapping_object_alter().
 */
function salesforce_term_ref_salesforce_pull_mapping_object_alter(&$mapping_object, &$sf_object, $mapping) {
  $sf_object['salesforce_mapping_id'] = $mapping->salesforce_mapping_id;
}
DamienMcKenna’s picture

@jimafisk: Great work! Thanks for working out the problem with term references. You might want to try uploading the submodule as a patch to the SF module for people to be able to use out of the box.

DamienMcKenna’s picture

@jimafisk: Just to mention it, though, the taxonomy term names weren't coming through when I used salesforce_term_ref's "taxonomy term" handler - I use hook_salesforce_push_params_alter() to examine the data being pushed and the terms fields are still empty.