12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- /**
- * @file
- * Installation file for Matomo Analytics module.
- */
- use Drupal\Core\Url;
- use Drupal\user\Entity\Role;
- /**
- * Implements hook_install().
- */
- function matomo_install() {
- // Make the default install more user and GDPR friendly.
- $role = Role::load('authenticated');
- $role->grantPermission('opt-in or out of matomo tracking');
- $success = $role->save();
- if ($success) {
- $messenger = \Drupal::messenger();
- $messenger->addMessage(t('Module %module granted %permission permission to authenticated users.', ['%module' => 'Matomo Analytics', '%permission' => t('Opt-in or out of tracking')]), 'status');
- }
- }
- /**
- * Implements hook_uninstall().
- *
- * Remove cache directory if module is uninstalled.
- */
- function matomo_uninstall() {
- matomo_clear_js_cache();
- }
- /**
- * Implements hook_requirements().
- */
- function matomo_requirements($phase) {
- $requirements = [];
- if ($phase == 'runtime') {
- $config = \Drupal::config('matomo.settings');
- // Raise warning if Matomo user account has not been set yet.
- if (!preg_match('/^\d{1,}$/', $config->get('site_id'))) {
- $requirements['matomo_site_id'] = [
- 'title' => t('Matomo module'),
- 'description' => t('Matomo module has not been configured yet. Please configure its settings from the <a href=":url">Matomo settings page</a>.', [':url' => Url::fromRoute('matomo.admin_settings_form')->toString()]),
- 'severity' => REQUIREMENT_WARNING,
- 'value' => t('Not configured'),
- ];
- }
- }
- return $requirements;
- }
|