You are here

eu_cookie_compliance.install in EU Cookie Compliance (GDPR Compliance) 2.0.x

Update scripts for the EU Cookie Compliance module.

File

eu_cookie_compliance.install
View source
<?php

/**
 * @file
 * Update scripts for the EU Cookie Compliance module.
 */
use Drupal\user\Entity\Role;

/**
 * Implements hook_schema().
 */
function eu_cookie_compliance_schema() {
  $schema['eu_cookie_compliance_basic_consent'] = [
    'description' => 'Basic consent storage for EU Cookie Compliance / GDPR.',
    'fields' => [
      'cid' => [
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique consent storage ID.',
      ],
      'uid' => [
        'description' => '{users}.uid for user.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'timestamp' => [
        'description' => 'Time of consent.',
        'type' => 'int',
        'unsigned' => FALSE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'ip_address' => [
        'description' => 'The IP address.',
        'type' => 'varchar',
        // Maximum length of an ipv6 IP address.
        'length' => 45,
        'not null' => TRUE,
        'default' => '',
      ],
      'consent_type' => [
        'description' => 'The type of consent, such as "banner" for the banner and form_id for forms.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ],
      'revision_id' => [
        'description' => 'Revision of the privacy policy at the time of consent.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'primary key' => [
      'cid',
    ],
    'indexes' => [
      'uid' => [
        'uid',
      ],
    ],
    'foreign keys' => [
      'uid' => [
        'users' => 'uid',
      ],
    ],
  ];
  return $schema;
}

/**
 * Implements hook_install().
 */
function eu_cookie_compliance_install() {
  module_load_include('module', 'eu_cookie_compliance', 'eu_cookie_compliance');
  $roles = Role::loadMultiple();
  $permission = 'display eu cookie compliance popup';
  foreach ($roles as $rid => $role) {
    user_role_grant_permissions($rid, [
      $permission,
    ]);
  }
  $config = \Drupal::configFactory()
    ->getEditable('eu_cookie_compliance.settings');
  if (!$config
    ->get('uuid')) {
    $config
      ->set('uuid', \Drupal::service('uuid')
      ->generate());
  }
  _eu_cookie_compliance_module_set_weight();
}

/**
 * Implements hook_requirements().
 */
function eu_cookie_compliance_requirements($phase) {
  $requirements = [];
  if ($phase === 'runtime') {
    $popup_link = Drupal::config('eu_cookie_compliance.settings')
      ->get('popup_link');
    $show_policy = Drupal::config('eu_cookie_compliance.settings')
      ->get('show_disagree_button');
    if ($popup_link === '<front>' && $show_policy) {
      $requirements['eu_cookie_compliance'] = [
        'title' => t('EU Cookie Compliance'),
        'severity' => REQUIREMENT_WARNING,
        'description' => t('Your privacy policy link is pointing at the front page. This is the default value after installation, and unless your privacy policy is actually posted at the front page, you will need to create a separate page for the privacy policy and link to that page.'),
        'value' => t('Privacy policy link not provided'),
      ];
    }
  }
  return $requirements;
}