posthog-1.0.0-alpha5/posthog.install

posthog.install
<?php

/**
 * @file
 * Install, update and uninstall functions for Posthog Analytics Integration.
 */

use Drupal\Core\Url;

/**
 * Implements hook_requirements().
 */
function posthog_requirements($phase) {
  $requirements = [];
  // If we are not in runtime phase, there is nothing to do. So bail out early.
  if ($phase !== 'runtime') {
    return [];
  }
  $config = \Drupal::config('posthog.settings');

  $host = $config->get('host');
  $apiKey = $config->get('api_key');

  $values = [];
  $showWarning = FALSE;
  if (empty($host)) {
    $values[] = t('Posthog host');
    $showWarning = TRUE;
  }
  if (empty($apiKey)) {
    $values[] = t('Posthog project API key');
    $showWarning = TRUE;
  }

  if ($showWarning) {
    // Either $host or $apiKey is empty. So we need to show a warning:
    $requirements['posthog'] = [
      'title' => t('Posthog configuration'),
      'severity' => REQUIREMENT_WARNING,
      'value' => \Drupal::translation()->formatPlural(count($values), 'Posthog %values is not set', 'Posthog %values are not set', ['%values' => implode(',', $values)]),
      'description' => \Drupal::translation()->formatPlural(count($values), 'Please configure the %values in the <a target="_blank" href=":url">Posthog settings</a>.', '%values values are not set', [
        '%values' => implode(',', $values),
        ':url' => Url::fromRoute('posthog.settings')->toString(),
      ]),
    ];
  }

  return $requirements;
}

/**
 * Rebuild the container, to remove old dependency injected service.
 */
function posthog_update_10001() {
  \Drupal::service('kernel')->rebuildContainer();
}

/**
 * Initialize the new "identify_anonymous" configuration.
 */
function posthog_update_10002() {
  \Drupal::configFactory()->getEditable('posthog.settings')
    ->set('identify_anonymous', FALSE)
    ->save();
}

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

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