You are here

function acquia_lift_page_build in Acquia Lift Connector 7.3

Same name and namespace in other branches
  1. 7 acquia_lift.module \acquia_lift_page_build()
  2. 7.2 acquia_lift.module \acquia_lift_page_build()

Implements hook_page_build().

File

./acquia_lift.module, line 82
acquia_lift.module Provides Acquia Lift Profiles integration.

Code

function acquia_lift_page_build(&$page) {

  // Bail if Acquia Lift has not yet been configured.
  if (!acquia_lift_is_configured()) {
    return;
  }

  // Bail if the path is a path to ignore
  $current_path = '/' . current_path();
  $alias_path = drupal_lookup_path('alias', current_path());
  $alias_path = $alias_path == FALSE ? $current_path : '/' . $alias_path;
  $patterns = variable_get('acquia_lift_ignore_path_patterns', '');
  if (drupal_match_path($current_path, $patterns) || drupal_match_path($alias_path, $patterns)) {
    return;
  }
  $assets_url = variable_get('acquia_lift_assets_url');
  $decision_api_url = variable_get('acquia_lift_decision_api_url', '');
  $oauth_url = variable_get('acquia_lift_oauth_url', '');

  // Add the credentials and configuration for the Lift Experience Builder.
  _acquia_lift_add_meta_tag('account_id', variable_get('acquia_lift_account_id'));
  _acquia_lift_add_meta_tag('site_id', variable_get('acquia_lift_site_id'));
  _acquia_lift_add_meta_tag('liftAssetsURL', $assets_url);
  if (!empty($decision_api_url)) {
    _acquia_lift_add_meta_tag('liftDecisionAPIURL', variable_get('acquia_lift_decision_api_url'));
  }
  if (!empty($oauth_url)) {
    _acquia_lift_add_meta_tag('authEndpoint', variable_get('acquia_lift_oauth_url'));
  }
  _acquia_lift_add_meta_tag('bootstrapMode', variable_get('acquia_lift_bootstrap_mode', 'auto'));
  _acquia_lift_add_meta_tag('contentReplacementMode', variable_get('acquia_lift_content_replacement_mode', 'untrusted'));
  _acquia_lift_add_meta_tag('contentOrigin', variable_get('acquia_lift_content_origin', ''));
  _acquia_lift_add_meta_tag('userAccess', variable_get('acquia_lift_user_access', ''));

  // If there are querystring parameters present corresponding to the configured
  // identity params, we add the identity and identity type to the meta tags.
  $identity_param = variable_get('acquia_lift_identity_param', '');
  $identity_type_param = variable_get('acquia_lift_identity_type_param', '');
  if (!empty($identity_param)) {
    $all_params = drupal_get_query_parameters();
    if (isset($all_params[$identity_param])) {

      // Set the identity type to the default either as specified by the user or
      // as the application default.
      $identity_type = variable_get('acquia_lift_default_identity_type') ?: ACQUIA_LIFT_DEFAULT_IDENTITY_TYPE_DEFAULT;
      if (!empty($identity_type_param) && !empty($all_params[$identity_type_param])) {

        // If an explicit identity type was passed in the query parameters then

        //use that instead.
        $identity_type = check_plain($all_params[$identity_type_param]);
      }
      $identity_value = check_plain($all_params[$identity_param]);
      _acquia_lift_add_meta_tag('identity:' . $identity_type, $identity_value);
    }
  }
  $page_context = acquia_lift_get_page_context();
  foreach ($page_context as $name => $value) {
    _acquia_lift_add_meta_tag($name, is_array($value) ? implode(',', $value) : $value);
  }

  // Add the lift js bootstrap loader
  $js_file = $assets_url . '/lift.js';
  $attached['js'][$js_file] = array(
    'type' => 'external',
    'weight' => JS_DEFAULT - 10,
    // Drupal 7 does not support rendering of 'async' in any non-hacky way,
    // I am still adding 'async' here in case Drupal 7 supports it in future.
    'async' => TRUE,
  );
  $css_path = drupal_get_path('module', 'acquia_lift') . '/css/acquia_lift.css';
  $attached['css'][$css_path] = array();
  $page['page_top']['acquia_lift'] = array(
    '#attached' => $attached,
  );
}