Allow expansion of custom fields when merging to include fields from other apps

eg: {{#other_app/#addressbook_cf/n_fn}}
This commit is contained in:
nathangray 2017-01-19 10:51:57 -07:00
parent a3562129b0
commit 6ed24454f9

View File

@ -1370,6 +1370,18 @@ abstract class Merge
preg_match_all('/\${2}(([^\/#]*?\/)?)#([^$\/]+)\/(.*?)[$}]{2}/', $content, $matches);
list($placeholders, , , $cf, $sub) = $matches;
// Collect any used custom fields from entries so you can do
// {{#other_app/#other_app_cf/n_fn}}
$expand_sub_cfs = [];
foreach($sub as $index => $cf_sub)
{
if(strpos($cf_sub, '#') === 0)
{
$expand_sub_cfs[$cf[$index]] .= '$$'.$cf_sub . '$$ ';
}
}
$expand_sub_cfs = array_unique($expand_sub_cfs);
foreach($cf as $index => $field)
{
if($cfs[$field])
@ -1400,9 +1412,10 @@ abstract class Merge
{
$classname = "{$field_app}_merge";
$class = new $classname();
// If we send the real content, it can result in infinite loop of lookups
// This means you can't do {{#other_app/#other_app_cf/n_fn}}
$content = '';
// If we send the real content it can result in infinite loop of lookups
// so we send only the used fields
$content = $expand_sub_cfs[$field] ? $expand_sub_cfs[$field] : '';
$app_replacements[$field] = $class->get_replacements($values['#'.$field], $content);
}
$replacements[$placeholders[$index]] = $app_replacements[$field]['$$'.$sub[$index].'$$'];