posthog-1.0.0-alpha5/modules/posthog_php/posthog_php.module
modules/posthog_php/posthog_php.module
<?php
/**
* @file
* Primary module hooks for Posthog PHP module.
*/
use Drupal\Component\Utility\Html;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\user\UserInterface;
/**
* Implements hook_user_login().
*/
function posthog_php_user_login(UserInterface $user) {
// Only identify the logged in user, if the setting is enabled:
if (!\Drupal::config('posthog_php.settings')->get('identify_users_on_login')) {
return;
}
$userAttributesProvider = \Drupal::service('posthog.user_attributes_provider');
/** @var \Drupal\posthog\CookieReader $cookieReader */
$userProperties = $userAttributesProvider->getUserProperties($user);
/** @var \Drupal\posthog_php\SdkInterface $posthogSdk */
$posthogSdk = \Drupal::service('posthog_php.sdk');
// Identify the user in posthog:
$posthogSdk->identify(
$userProperties,
);
}
/**
* Implements hook_help().
*/
function posthog_php_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.posthog_php':
$text = file_get_contents(__DIR__ . '/README.md');
if (!\Drupal::moduleHandler()->moduleExists('markdown')) {
return '<pre>' . Html::escape($text) . '</pre>';
}
else {
// Use the Markdown filter to render the README.
$filter_manager = \Drupal::service('plugin.manager.filter');
$settings = \Drupal::configFactory()->get('markdown.settings')->getRawData();
$config = ['settings' => $settings];
$filter = $filter_manager->createInstance('markdown', $config);
return $filter->process($text, 'en');
}
}
return NULL;
}
