function google_tag_requirements in GoogleTagManager 7
Same name and namespace in other branches
- 8 google_tag.install \google_tag_requirements()
- 7.2 google_tag.install \google_tag_requirements()
Implements hook_requirements().
File
- ./
google_tag.install, line 56 - Provides install, update, and uninstall functions.
Code
function google_tag_requirements($phase) {
$t = get_t();
$requirements = array();
if ($phase == 'runtime') {
if (!preg_match('/^GTM-\\w{4,}$/', variable_get('google_tag_container_id', ''))) {
// Google Tag Manager container ID has not been set.
$args = array(
'@path' => '/admin/config/system/google_tag',
);
$description = $t('Configure this integration module on its <a href="@path">settings page</a>.', $args);
$requirements['google_tag'] = array(
'title' => $t('Google Tag Manager'),
'description' => $description,
'severity' => REQUIREMENT_WARNING,
'value' => $t('Not configured'),
);
}
}
if ($phase == 'runtime' || $phase == 'update' || $phase == 'install') {
// Adapted from system_requirements().
$directory = 'public://google_tag';
module_load_include('inc', 'google_tag', 'includes/admin');
if (!is_dir($directory) || !_google_tag_is_writable($directory) || !_google_tag_is_executable($directory)) {
_file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
}
$is_executable = _google_tag_is_executable($directory);
$is_writable = _google_tag_is_writable($directory);
$is_directory = is_dir($directory);
if (!$is_executable || !$is_writable || !$is_directory) {
// The snippet directory does not exist or is not writable or searchable.
// If applicable, get the directory path of stream wrapper.
$wrapper = file_stream_wrapper_get_instance_by_uri($directory);
if (method_exists($wrapper, 'getDirectoryPath') && ($path = $wrapper
->getDirectoryPath())) {
// getDirectoryPath() is not defined in StreamWrapperInterface; it
// exists in LocalStream and the local storage replacement classes in
// google_appengine; s3fs returns an empty string.
$path .= '/google_tag';
}
elseif (!($path = $wrapper
->getExternalUrl())) {
$path = $directory;
}
if (!$is_directory) {
$error = $t('The directory %directory does not exist.', array(
'%directory' => $path,
));
$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');
}
elseif (!$is_writable) {
$error = $t('The directory %directory is not writable.', array(
'%directory' => $path,
));
$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');
}
else {
$error = $t('The directory %directory is not searchable.', array(
'%directory' => $path,
));
$description = $t('An automated attempt to make the directory searchable failed, possibly due to a permissions problem. Make the directory searchable.');
$value = $t('Not searchable');
}
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 = '';
}
$requirements['google_tag_snippet_directory'] = array(
'title' => $t('Google Tag Manager snippet directory'),
'description' => "{$error} {$description}",
'severity' => REQUIREMENT_ERROR,
'value' => $value,
);
}
}
return $requirements;
}