You are here

function acquia_lift_get_option_set_editable_settings in Acquia Lift Connector 7.2

Helper function to generate editable JavaScript settings for an option set.

Parameters

stdClass $option_set: The option set to generate settings for.

Return value

array An array of settings to be added to JavaScript.

2 calls to acquia_lift_get_option_set_editable_settings()
acquia_lift_element_variation_details_form_ajax_callback in ./acquia_lift.admin.unibar.inc
Responds to AJAX submission of a variation type details page.
acquia_lift_personalize_option_set_render in ./acquia_lift.module
Implements hook_personalize_option_set_render().

File

./acquia_lift.module, line 941
acquia_lift.module Provides Acquia Lift-specific personalization functionality.

Code

function acquia_lift_get_option_set_editable_settings($option_set) {
  $js_osid = personalize_stringify_osid($option_set->osid);
  $option_set_settings = array();
  if ($option_set->plugin === 'elements') {

    // Personalize elements are always editable, but only deletable if not
    // used in targeting in a running/competed campaign.
    $agent_data = personalize_agent_load($option_set->agent);
    if ($agent_data->plugin === 'acquia_lift_target') {
      module_load_include('inc', 'acquia_lift', 'acquia_lift.admin');
      $changes_enabled = acquia_lift_target_definition_changes_allowed($agent_data);
      foreach ($option_set->options as $option) {
        $is_control = $option['option_id'] === PERSONALIZE_CONTROL_OPTION_ID;
        $option_set_settings['acquia_lift']['option_sets'][$js_osid][$option['option_id']]['deletable'] = !$is_control && ($changes_enabled || !acquia_lift_target_option_targeted($agent_data->machine_name, $option['option_id']));
        $option_set_settings['acquia_lift']['option_sets'][$js_osid][$option['option_id']]['editable'] = !$is_control;
      }
    }
  }
  else {

    // Other types of options are not editable or deletable from the unibar.
    foreach ($option_set->options as $option) {
      $option_set_settings['acquia_lift']['option_sets'][$js_osid][$option['option_id']]['deletable'] = FALSE;
      $option_set_settings['acquia_lift']['option_sets'][$js_osid][$option['option_id']]['editable'] = FALSE;
    }
  }
  return $option_set_settings;
}