function acquia_lift_personalize_option_set_render in Acquia Lift Connector 7.2
Same name and namespace in other branches
- 7 acquia_lift.module \acquia_lift_personalize_option_set_render()
Implements hook_personalize_option_set_render().
File
- ./
acquia_lift.module, line 867 - acquia_lift.module Provides Acquia Lift-specific personalization functionality.
Code
function acquia_lift_personalize_option_set_render(&$element, $option_set) {
// For administrative users and Acquia Lift target agents, indicate if option
// sets are deletable (only applicable to personalize elements sets).
if (user_access('manage personalized content')) {
$option_set_settings = acquia_lift_get_option_set_editable_settings($option_set);
$element['#attached']['js'][] = array(
'type' => 'setting',
'data' => $option_set_settings,
);
}
if (empty($option_set->targeting)) {
return;
}
$rules = $option_set->targeting;
// We add our own settings for nested agents as they won't have been added
// by personalize.
$settings = acquia_lift_target_default_js_settings($option_set->agent);
$assets = array(
'js' => array(),
);
foreach ($rules as $rule) {
if (isset($rule['option_id']) || !isset($rule['osid'])) {
continue;
}
$child_os = personalize_option_set_load($rule['osid']);
// Make sure the agent assets are available for the child OS.
$nested_agent = personalize_agent_load($child_os->agent);
// If the test agent has a site name property, then this is used as a prefix
// for decision and goal names.
$site_name_prefix = !empty($nested_agent->data['site_name']) ? $nested_agent->data['site_name'] . '-' : '';
$child_settings = personalize_agent_get_map_settings($child_os->agent, $child_os, $assets);
$child_settings['site_name_prefix'] = $site_name_prefix;
$settings['agent_map'][$child_os->agent] = $child_settings;
$settings['option_sets'] += _personalize_convert_option_set_to_js_setting($child_os);
}
$settings_array = array(
'type' => 'setting',
'data' => array(
'acquia_lift_target' => $settings,
),
);
$assets['js'] = array_merge_recursive($assets['js'], array(
$settings_array,
));
personalize_merge_element_assets($element, $assets);
}