You are here

function acquia_lift_profiles_admin_form in Acquia Lift Connector 7.2

Same name and namespace in other branches
  1. 7 acquia_lift_profiles/acquia_lift_profiles.admin.inc \acquia_lift_profiles_admin_form()

Admin form for configuring acquia_lift_profiles behavior.

1 string reference to 'acquia_lift_profiles_admin_form'
acquia_lift_profiles_menu in acquia_lift_profiles/acquia_lift_profiles.module
Implements hook_menu().

File

acquia_lift_profiles/acquia_lift_profiles.admin.inc, line 75
acquia_lift_profiles.admin.inc Provides functions needed for the admin UI.

Code

function acquia_lift_profiles_admin_form($form, &$form_state) {
  $form['#attached']['js'][] = drupal_get_path('module', 'acquia_lift_profiles') . '/js/acquia_lift_profiles.admin.js';
  $identity_parameter_display_value = variable_get('acquia_lift_profiles_identity_param') ?: 'identity';
  $identity_type_parameter_display_value = variable_get('acquia_lift_profiles_identity_type_param') ?: 'identityType';
  $default_identity_type_display_value = variable_get('acquia_lift_profiles_default_identity_type') ?: 'account';
  $default_identity_type_default_value = variable_get('acquia_lift_profiles_default_identity_type') ?: ACQUIA_LIFT_PROFILES_DEFAULT_IDENTITY_TYPE_DEFAULT;
  $user_email_verification_value = variable_get('user_email_verification', TRUE);
  $form['acquia_lift_profiles_identity'] = array(
    '#title' => t('Identity'),
    '#type' => 'fieldset',
    '#tree' => TRUE,
  );
  $capture_identity_title = 'Capture identity on login';
  $capture_identity_title .= $user_email_verification_value ? ' (note: register is not captured because the site requires user email verification)' : ' and register';
  $form['acquia_lift_profiles_identity']['acquia_lift_profiles_capture_identity'] = array(
    '#type' => 'checkbox',
    '#title' => t($capture_identity_title),
    '#description' => t('Check this if you want Acquia Lift Profiles to capture the identity of the user upon login or registration. This means sending their email address to the Acquia Lift Profile Manager.'),
    '#default_value' => variable_get('acquia_lift_profiles_capture_identity', FALSE),
  );
  $form['acquia_lift_profiles_identity']['acquia_lift_profiles_identity_param'] = array(
    '#type' => 'textfield',
    '#title' => t('Identity parameter'),
    '#description' => t('The query string parameter for specific visitor information, such as an email address or social media username, which is sent to the Acquia Lift service. Example: ?<ins>@identity_parameter_display_value</ins>=jdoe01', array(
      '@identity_parameter_display_value' => $identity_parameter_display_value,
    )),
    '#default_value' => variable_get('acquia_lift_profiles_identity_param', ''),
  );
  $form['acquia_lift_profiles_identity']['acquia_lift_profiles_identity_type_param'] = array(
    '#type' => 'textfield',
    '#title' => t('Identity type parameter'),
    '#description' => t('The query string parameter for the category (standard or custom) of the visitor\'s identity information, as defined in the !help_link. Example: ?@identity_parameter_display_value=jdoe01&<ins>@identity_type_parameter_display_value</ins>=@default_identity_type_default_value', array(
      '@identity_parameter_display_value' => $identity_parameter_display_value,
      '@identity_type_parameter_display_value' => $identity_type_parameter_display_value,
      '@default_identity_type_default_value' => $default_identity_type_default_value,
      '!help_link' => l(t('Acquia Lift service'), 'https://docs.acquia.com/lift/offers/admin/customer#custom-identifier', array(
        'attributes' => array(
          'target' => '_blank',
        ),
      )),
    )),
    '#default_value' => variable_get('acquia_lift_profiles_identity_type_param', ''),
    '#states' => array(
      'visible' => array(
        ':input[name="acquia_lift_profiles_identity[acquia_lift_profiles_identity_param]"]' => array(
          '!value' => '',
        ),
      ),
    ),
  );
  $form['acquia_lift_profiles_identity']['acquia_lift_profiles_default_identity_type'] = array(
    '#type' => 'textfield',
    '#title' => t('Default identity type'),
    '#attributes' => array(
      'placeholder' => ACQUIA_LIFT_PROFILES_DEFAULT_IDENTITY_TYPE_DEFAULT,
    ),
    '#description' => t('The identity type category to use by default. Leave this field blank to default to <ins>@default</ins>. Example: <ins>@default_identity_type_display_value</ins> is "?@identity_parameter_display_value=jdoe01&@identity_type_parameter_display_value=<ins>@default_identity_type_display_value</ins>", while blank is the same as "?@identity_parameter_display_value=jdoe01&@identity_type_parameter_display_value=<ins>@default</ins>"', array(
      '@default' => ACQUIA_LIFT_PROFILES_DEFAULT_IDENTITY_TYPE_DEFAULT,
      '@identity_parameter_display_value' => $identity_parameter_display_value,
      '@identity_type_parameter_display_value' => $identity_type_parameter_display_value,
      '@default_identity_type_display_value' => $default_identity_type_display_value,
    )),
    '#default_value' => variable_get('acquia_lift_profiles_default_identity_type', ''),
  );

  // Retrieving all context options.
  module_load_include('inc', 'personalize', 'personalize.admin');
  $groups = personalize_get_grouped_context_options(NULL, TRUE, array(
    'acquia_lift_profiles_context',
    'acquia_lift_context',
  ));

  // Field mappings.
  $form['acquia_lift_profiles_field_mappings'] = array(
    '#title' => t('Field Mappings'),
    '#description' => t('For the "content section", "content keywords", and "persona" fields in Acquia Lift Profiles, you can map them to different visitor contexts.'),
    '#type' => 'fieldset',
    '#tree' => TRUE,
  );
  $field_list = array(
    'content_section' => 'Content Section',
    'content_keywords' => 'Content Keywords',
    'persona' => 'Persona',
  );
  $field_mappings = variable_get('acquia_lift_profiles_field_mappings', array());
  foreach ($field_list as $field_name => $field_friendly_name) {
    $default_value = isset($field_mappings[$field_name]) ? $field_mappings[$field_name] : NULL;
    $select = acquia_lift_profiles_admin_build_visitor_context_select($groups, $default_value);
    $form['acquia_lift_profiles_field_mappings'][$field_name] = $select;
    $form['acquia_lift_profiles_field_mappings'][$field_name]['#title'] = t($field_friendly_name);
  }

  // Only show the "Tracked actions" selector if acquia_lift_profiles has already been
  // configured for API connections.
  if (acquia_lift_profiles_is_configured(TRUE)) {
    $udf_mappings = variable_get('acquia_lift_profiles_udf_mappings', array());
    $form['acquia_lift_profiles_udf_mappings'] = array(
      '#title' => t('User Defined Field Mappings'),
      '#description' => t('For each user defined field available in Acquia Lift Profiles, you can map a visitor context, whose value will then be sent as the value for that user defined field.'),
      '#type' => 'fieldset',
      '#tree' => TRUE,
    );
    foreach (acquia_lift_profiles_get_udfs() as $type => $udfs) {
      $form['acquia_lift_profiles_udf_mappings'][$type] = array(
        '#title' => t('@type mappings', array(
          '@type' => ucfirst($type),
        )),
        '#type' => 'fieldset',
        '#tree' => TRUE,
      );

      // Start by just showing 3 of each type to map, or if more have already
      // been mapped show that number plus 1.
      $max = count($udfs);
      $min = 3;
      if (isset($udf_mappings[$type])) {
        if (count($udf_mappings[$type]) < $max) {
          $min = max(array(
            count($udf_mappings[$type]) + 1,
            3,
          ));
        }
        else {
          $min = $max;
        }
      }
      foreach ($udfs as $i => $udf) {
        $default_value = isset($udf_mappings[$type][$udf]) ? $udf_mappings[$type][$udf] : NULL;
        $select = acquia_lift_profiles_admin_build_visitor_context_select($groups, $default_value);
        $select['#title'] = t('Context to map to the @field field', array(
          '@field' => $udf,
        ));
        $form['acquia_lift_profiles_udf_mappings'][$type][$udf] = $select;
        if ($i == $min) {
          $form['acquia_lift_profiles_udf_mappings'][$type][$udf]['#prefix'] = '<div class="acquia-lift-profiles-hidden-udfs">';
        }
        if ($i == $max - 1) {
          $form['acquia_lift_profiles_udf_mappings'][$type][$udf]['#suffix'] = '</div>';
        }
      }
      if ($min < $max) {
        $form['acquia_lift_profiles_udf_mappings'][$type]['button__show_all'] = array(
          '#attributes' => array(
            'class' => array(
              'acquia-lift-profiles-udf-show-all',
            ),
          ),
          '#type' => 'button',
          '#value' => t('Show all'),
        );
      }
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}