acquia_vwo-1.0.x-dev/acquia_vwo.module

acquia_vwo.module
<?php

/**
 * @file
 * Acquia VWO module file.
 */

use Drupal\Core\Render\Markup;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_help().
 */
function acquia_vwo_help($route_name, RouteMatchInterface $route_match) {
  // Add help file on Acquia VWO routes.
  if ($route_name == 'help.page.acquia_vwo' || str_starts_with($route_name, 'acquia_vwo.settings')) {
    \Drupal::moduleHandler()->loadInclude('acquia_vwo', 'inc', 'acquia_vwo.help');
  }
  $help = [];

  // Show help page for each route respectively.
  switch ($route_name) {
    case 'help.page.acquia_vwo':
      $help = acquia_vwo_help_settings();
      $vwo_settings = Url::fromRoute('acquia_vwo.settings');
      $help[] = t(
        'Once the Account ID has been set on the <a href=":url">settings page</a>, the configuration of your A/B and other tests is done by logging into your account on the VWO website.',
        [':url' => $vwo_settings->toString()]
      );
      break;
  }

  $help_text = '<p>' . implode('</p><p>', $help) . '</p>';

  return $help_text;
}

/**
 * Implements hook_page_attachments_alter().
 */
function acquia_vwo_page_attachments_alter(array &$page) {

  // Add user control script and Drupal settings.
  /** @var Drupal\acquia_vwo\Service\User\UserControl $user_control */
  $user_control = \Drupal::service('acquia_vwo.service.user.user_control');
  $user_control->addUserOptScript($page);

  // Ignore admin paths.
  if (\Drupal::service('router.admin_context')->isAdminRoute()) {
    return;
  }

  // Add VWO scripts.
  /** @var Drupal\acquia_vwo\Service\Context\PageContext $page_context */
  $page_context = \Drupal::service('acquia_vwo.service.context.page_context');
  $page_context->populate($page);
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function acquia_vwo_form_user_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  /** @var Drupal\acquia_vwo\Service\User\UserControl $user_control */
  $user_control = \Drupal::service('acquia_vwo.service.user.user_control');
  $user_control->userFormAlter($form);
}

/**
 * Submit handler to save user choice on VWO code opt in/out.
 */
function acquia_vwo_form_user_form_alter_submit($form, FormStateInterface $form_state) {
  /** @var Drupal\acquia_vwo\Service\User\UserControl $user_control */
  $user_control = \Drupal::service('acquia_vwo.service.user.user_control');
  $user_control->saveUserData('user_opt', $form_state->getValue('user_opt'));
}

/**
 * Implements hook_requirements().
 */
function acquia_vwo_requirements($phase) {
  if ($phase !== 'runtime') {
    return [];
  }

  // Check if VWO module is enabled.
  $moduleHandler = \Drupal::service('module_handler');
  if (!$moduleHandler->moduleExists('vwo')) {
    return [];
  }

  return [
    'acquia_vwo' => [
      'title' => t('Acquia VWO'),
      'value' => t('VWO module is also enabled.'),
      'description' => t('Acquia VWO is the alternative module for VWO integration. Please uninstall the VWO module.'),
      'severity' => REQUIREMENT_ERROR,
    ]
  ];
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc