Open main menu

Changes

1,990 bytes added ,  19:20, 27 October 2015
more details
When I click "Preview as HTML", the value is correctly displayed for the first contact in my "Recipient list". The token is {contact.custom_71}
I used a breakpoint in <code>civicrm/api/V3/Mailing.php</code> at '''line 536''' where $details gets populated from a call to <source lang=php inline>CRM_Utils_Token::getTokenDetails($mailingParams, $returnProperties, TRUE, TRUE, NULL, $mailing->getFlattenedTokens())</source>
At that point, the variable $this is a CRM_Mailing_BAO object. $this->tokens is an array[3] with keys html, text, subject
$tokens['html'] is an array[4] with keys contact, general, domain, action<ref>this expands to include 'stats' when you use one of those tokens in your message</ref><br />
$tokens['html']['contact'] is an array[3] with values 'first_name', 'custom_40' and 'custom_71' <br />
$tokens['html']['general'] is an array[2] with values 'wUrl', 'custom_40' <br />
$tokens['html']['domain'] is an array[1] with values 'address' <br />
$tokens['html']['action'] is an array[1] with values 'optOutUrl' <br />
 
 
At this point, $body_html contains the un-evaluated html (meaning the tokens are still present in their literal form).
getKeyID is called and for $key "custom_71", it returns "71" since $all is bool 0
Those values populate $cfID and in turn $custom[], so that now $custom is array("40", "71") (and also "72" when a singular value custom field is added - indicating that this is the correct place for this info to be found)
We then go through the autoloader mechanism for "CRM_Contact_BAO_Query"
$contactDetais[2][custom_40] = "https://freephile.org/wiki/Main_Page"
$contactDetais[2][custom_71] = "Not, Never, Well Maybe"
 
So $details '''has the data''' and $contactDetails is a reference to it as well.
 
On '''line 1264''', there is a foreach loop that runs through $custom and assigns values into $contactDetails[$contactID]["custom_{$cfID}"] but those are ALREADY correct, so is this just a formatter? CustomField::getDisplayValue() is called, which calls self::getDisplayValueCommon(). When CustomField::getDisplayValue($value, $id, &$options, $contactID = NULL, $fieldID = NULL) is called, $value is https://freephile.org/wiki/Main_Page, $id is "40", $options is an array of the custom values we care about with an 'attributes' key and I think $contactID was actually null. In any case, it's clear that these are formatter functions and the 'text' html element is returned as is, unless it's an array in which case it's imploded with commas (line 1309 of CustomField).
 
We jump back to "Mailing.php" line 538 where $mailing->compose() is called.
 
I then notice that we jumped to MagicFunctionProvider.php where invoke($apiRequest) is called, but only the contact.first_name is replaced correctly in the $result['values']['body_html']
 
on '''line 98''', kernel.php fills in $apiResponse using $this->respond($apiProvider, $apiRequest, $result); but as just noted, $result doesn't have the custom tokens replaced.
 
When EventDispatcher::getListeners() is called, $this->listeners has hook_civicrm_post::Activity and hook_civicrm_post::Case so it's not a place where our custom data hooks are involved.
 
 
 
CRM_Utils_Hook_DrupalBase::CRM_Utils_Hook->invoke() is called which builds the module list and runs the hooks.
Then runHooks() in <code>CRM/Utils/Hook.php</code> is called; and it's called with <source lang=php>$civiModules, $fnSuffix, $numParams, &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6</source>
$arg6 is null
</pre>
 
Note: it also gets called with $fnSuffix = "civicrm_apiWrappers" so the hook function would be hook_civicrm_apiWrappers()
== Results ==
4,558

edits