In the 6.x version of the salesforce API, it was possible to enter PHP code as the Drupal value of a field mapping. This is no longer provided in the 7.x version of the module.
I considered using tokens to provide my custom value, but the Mapping UI does not seem to read tokens for the mapped Drupal entity. E.g. I am mapping Drupal Commerce Order to Salesforce Opportunity. When I select "Token" for the Drupal field value, the list of Tokens supported does not include tokens for the Commerce Order entity.
Any suggestions on how to approach this would be greatly appreciated. Either how to provide a PHP-code field type for Drupal field mappings, or how to get the existing Token field type to see the tokens provided by the chosen entity.
Thanks!
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | Salesforce-Tokens_for_Commerce-1927434-4.patch | 1.24 KB | mariacha1 |
Comments
Comment #1
tauno commentedYou can use PHP in mappings by implementing hook_salesforce_push_params_alter() and/or hook_salesforce_pull_entity_value_alter(). You should be able to do most anything you need to with that.
It does look like tokens for commerce_order entities (and maybe other entities) are not showing up in the mapping UI. It does work for registration entities, so it's not an issue for all entity types. Worth looking into a little further.
Comment #2
kostajh commented@benjaminbradley is this still an issue with the latest dev releases of Drupal Commerce and Salesforce Suite?
Comment #3
mariacha1 commentedI can confirm that not all tokens are being called into the list populated when you select the "Commerce Order entity in the latest version of 7.x-3.x.
The problem seems to be this bit of code in salesforce_mapping.admin.inc:
The problem is that $drupal_entity_type for Commerce Order entities is "commerce_order". BUT the tokens we're looking for are "commerce-order" (dash instead of underscore).
I wish it were as easy as converting all underscores to dashes, but it looks like there's a controversy over whether or not my_entity_name is a valid token key in issues like this #1272560: Entity tokens duplicates field tokens created by token module.
So we can't count on ALL tokens being dashes instead of underscores.
I'm trying to find a function that can list all token keys for a given entity type. I'll reply with a patch if I figure it out.
Comment #4
mariacha1 commentedHere's my attempt at a patch. It's not pretty, but it seems to work. Couldn't find a good way to pull in the available tokens for a given entity, so I just did an if/then call.
Comment #5
ryan.ryan commentedPatch applies cleanly
Comment #6
kenorb commentedComment #8
nadavoid commentedThank you for the patch, @mariacha1. I added a comment and committed it to 7.x-3.x.