You are here

function acquia_lift_inspector_page_attachments in Acquia Lift Connector 8.3

Same name and namespace in other branches
  1. 8.4 modules/acquia_lift_inspector/acquia_lift_inspector.module \acquia_lift_inspector_page_attachments()

Implements hook_page_attachments().

File

modules/acquia_lift_inspector/acquia_lift_inspector.module, line 26
Drupal Module: Acquia Lift Inspector.

Code

function acquia_lift_inspector_page_attachments(array &$page) {

  // Create and attach settings and library only when path context agrees on attaching.
  $path_context = \Drupal::service('acquia_lift.service.context.path_context');
  if (!$path_context
    ->shouldAttach()) {
    return;
  }

  // Get the config settings to see if the lift inspector is enabled.
  $config = \Drupal::config('acquia_lift.settings');
  $decision_api_url = $config
    ->get('credential.decision_api_url');

  // @TODO: find out how we can utilize an API method from the decision API to
  // get this information.
  switch ($decision_api_url) {
    case "https://eu-central-1-decisionapi.lift.acquia.com":
      $profile_manager_url = "https://eu-central-1.lift.acquia.com";
      break;
    case "https://us-east-1-demo-decisionapi.lift.acquia.com":
      $profile_manager_url = "https://demo.lift.acquia.com";
      break;
    case "https://eu-central-1-rc-decisionapi.dev.lift.acquia.com":
      $profile_manager_url = "https://eu-central-1-rc-web-my.dev.lift.acquia.com";
      break;
    default:
      $profile_manager_url = "https://us-east-1.lift.acquia.com";
      break;
  }

  // Attach the library and pass the profile manager URL to drupalSettings.
  if ($profile_manager_url) {
    $page['#attached']['library'][] = 'acquia_lift_inspector/acquia-lift-inspector';
    $page['#attached']['drupalSettings']['acquia_lift_inspector']['profile_manager_url'] = $profile_manager_url;
  }
}