etracker-8.x-3.x-dev/modules/cookies_etracker/cookies_etracker.install

modules/cookies_etracker/cookies_etracker.install
<?php

/**
 * @file
 * Requirements and update functions for the cookies_etracker module.
 */

use Drupal\Core\Url;

/**
 * @file
 * Installation information for the 'Cookies eTracker Analytics' module.
 */

/**
 * Implements hook_install().
 */
function cookies_etracker_install(): void {
  // Load cookies_etracker module after the third-party library.
  module_set_weight('cookies_etracker', 11);

  // Enable data_block_cookies to ensure cookies are blocked after
  // the module has been enabled.
  $config_factory = \Drupal::configFactory();
  $config = $config_factory->getEditable('etracker.settings');
  $etracker_script_settings = $config->get('etracker_script_settings');
  if (empty($etracker_script_settings['data_block_cookies'])) {
    $etracker_script_settings['data_block_cookies'] = TRUE;
    $config->set('etracker_script_settings', $etracker_script_settings);
    $config->save(TRUE);
  }

  \Drupal::messenger()->addMessage(t('COOKiES eTracker was installed successfully.<br />
    "Privacy: Disable cookies" setting was enabled automatically to ensure eTracker cookies are
    blocked until you <a href=":configure-url">finalize your configuration here</a>.', [':configure-url' => Url::fromRoute('etracker.admin_settings_form')->toString()]));
}

/**
 * Update service config to enforce module dependency 'cookies_etracker'.
 */
function cookies_etracker_update_8001(): void {
  $config = \Drupal::configFactory()
    ->getEditable('cookies.cookies_service.analytics');
  if (!$config->isNew()) {
    $dependencies = $config->get('dependencies');
    $dependencies['enforced']['module'][] = 'cookies_etracker';
    $config->set('dependencies', $dependencies)->save(TRUE);
  }
}

/**
 * Set default config for new configuration key 'knockout_mode'.
 */
function cookies_etracker_update_8002(): void {
  $config_factory = \Drupal::configFactory();
  $config = $config_factory->getEditable('cookies_etracker.settings');
  $knockout_mode = $config->get('knockout_mode');
  if (empty($knockout_mode)) {
    // Set data_block_cookies_advanced to the previously existing behavior.
    $config->set('knockout_mode', 'block_cookies_true_without_consent');
    $config->save(TRUE);
  }
}

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

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