You are here

acquia_lift.module in Acquia Lift Connector 8

Drupal Module: Acquia Lift

Acquia Lift lets you track customers' behavior throughout their buying journey — from anonymous visitor through to loyal customer. Acquia Lift allows you to create a unified customer profile for each individual, based on their interactions with your website. Using these profiles, Acquia Lift adaptively segments customers in real-time, letting you deliver personalized content that furthers your website visitors' engagement with your brand.

File

acquia_lift.module
View source
<?php

/**
 * @file
 * Drupal Module: Acquia Lift
 *
 * Acquia Lift lets you track customers' behavior throughout their buying
 * journey — from anonymous visitor through to loyal customer. Acquia Lift
 * allows you to create a unified customer profile for each individual, based
 * on their interactions with your website. Using these profiles, Acquia Lift
 * adaptively segments customers in real-time, letting you deliver personalized
 * content that furthers your website visitors' engagement with your brand.
 */
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\user\UserInterface;
use Drupal\node\NodeInterface;
use Drupal\acquia_lift\Service\Helper\SettingsHelper;

/**
 * Implements hook_help().
 */
function acquia_lift_help($route_name, RouteMatchInterface $route_match) {
  return \Drupal::service('acquia_lift.service.helper.help_message_helper')
    ->getMessage($route_name);
}

/**
 * Implements hook_page_attachments().
 */
function acquia_lift_page_attachments(array &$attachments) {

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

  // Prepare credential drupal settings.
  $credential_settings = \Drupal::config('acquia_lift.settings')
    ->get('credential');
  $drupal_settings['credential'] = SettingsHelper::getFrontEndCredentialSettings($credential_settings);

  // Prepare page context.
  $page_context = \Drupal::service('acquia_lift.service.context.page_context');
  $request = \Drupal::request();

  // Set page context by node.
  if ($request->attributes
    ->has('node')) {
    $node = $request->attributes
      ->get('node');
    if ($node instanceof NodeInterface) {
      $page_context
        ->setByNode($node);
    }
  }

  // Set page context's title.
  $route_object = \Drupal::routeMatch()
    ->getRouteObject();
  $title_resolver = \Drupal::service('title_resolver');
  $title = $title_resolver
    ->getTitle($request, $route_object);
  $page_context
    ->setPageContextTitle($title);
  $drupal_settings['pageContext'] = $page_context
    ->getAll();

  // Attach identity settings.
  $identity = \Drupal::service('acquia_lift.service.context.path_context')
    ->getIdentity();
  if ($identity) {
    $drupal_settings['identity'] = $identity;
  }

  // Attach JavaScript library and settings.
  $attachments['#attached']['library'][] = 'acquia_lift/acquia_lift';
  $attachments['#attached']['drupalSettings']['acquia_lift'] = $drupal_settings;
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function acquia_lift_form_node_type_form_alter(array &$form, FormStateInterface &$form_state) {
  $node_type = $form_state
    ->getFormObject()
    ->getEntity()
    ->id();
  $form['acquia_lift'] = \Drupal::service('acquia_lift.service.helper.node_type_thumbnail_form_helper')
    ->getForm($node_type);
  $form['actions']['submit']['#submit'][] = 'acquia_lift_form_node_type_form_submit';
}

/**
 * Submit handler for the node type form with acquia lift options.
 *
 * @see acquia_lift_form_node_type_form_alter().
 */
function acquia_lift_form_node_type_form_submit(array $form, FormStateInterface &$form_state) {
  $node_type = $form_state
    ->getFormObject()
    ->getEntity()
    ->id();
  $settings = $form_state
    ->getValue('acquia_lift');
  \Drupal::service('acquia_lift.service.helper.node_type_thumbnail_form_helper')
    ->saveSettings($node_type, $settings);
}

/**
 * On user login (and user register) event, capture identity.
 *
 * Implements hook_user_login().
 */

//function acquia_lift_user_login(UserInterface $user) {

//  \Drupal::service('acquia_lift.service.context.path_context')->setIdentityByUser($user);

//}

Functions

Namesort descending Description
acquia_lift_form_node_type_form_alter Implements hook_form_FORM_ID_alter().
acquia_lift_form_node_type_form_submit Submit handler for the node type form with acquia lift options.
acquia_lift_help Implements hook_help().
acquia_lift_page_attachments Implements hook_page_attachments().