-
Notifications
You must be signed in to change notification settings - Fork 1
/
google_tag.install
70 lines (67 loc) · 2.72 KB
/
google_tag.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* @file
* Provides install, update, and uninstall functions.
*
* @author Jim Berry ("solotandem", http://drupal.org/user/240748)
*/
use Drupal\Core\StreamWrapper\PublicStream;
/**
* Implements hook_requirements().
*/
function google_tag_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
$config = \Drupal::config('google_tag.settings');
if (!preg_match('/^GTM-\w{4,}$/', $config->get('container_id'))) {
// Google Tag Manager container ID has not been set.
$requirements['google_tag'] = array(
'title' => t('Google Tag Manager'),
'description' => t('Configure this integration module on its <a href=":url">settings page</a>.', array(':url' => \Drupal::url('google_tag.settings_form'))),
'severity' => REQUIREMENT_WARNING,
'value' => t('Not configured'),
);
}
}
if ($phase == 'runtime' || $phase == 'install') {
// Adapted from system_requirements().
$directory = PublicStream::basePath() . '/js';
if (!is_dir($directory) || !is_writable($directory)) {
file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
}
$is_writable = is_writable($directory);
$is_directory = is_dir($directory);
if (!$is_writable || !$is_directory) {
// The snippet directory does not exist or is not writable.
if (!$is_directory) {
$error = t('The directory %directory does not exist.', array('%directory' => $directory));
$description = t('An automated attempt to create the directory failed, possibly due to a permissions problem. Create the directory and make it writable.');
$value = t('Does not exist');
}
else {
$error = t('The directory %directory is not writable.', array('%directory' => $directory));
$description = t('An automated attempt to make the directory writable failed, possibly due to a permissions problem. Make the directory writable.');
$value = t('Not writable');
}
if ($phase == 'install') {
$description .= t(' For more information, see INSTALL.txt or the <a href=":handbook_url">online handbook</a>.', array(':handbook_url' => 'https://www.drupal.org/server-permissions'));
$value = '';
}
$description = array(
'#type' => 'inline_template',
'#template' => '{{ error }} {{ description }}',
'#context' => array(
'error' => $error,
'description' => $description,
),
);
$requirements['google_tag_snippet_directory'] = array(
'title' => t('Google Tag Manager snippet directory'),
'description' => $description,
'severity' => REQUIREMENT_ERROR,
'value' => $value,
);
}
}
return $requirements;
}