Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cms 2193 update d9 #4

Open
wants to merge 2 commits into
base: dennis-8.x-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion google_tag.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ name: 'Google Tag Manager'
type: module
description: 'Allows your website analytics to be managed using Google Tag Manager.'
package: 'Statistics'
core: 8.x
core_version_requirement: ^8 || ^9
configure: google_tag.settings_form
8 changes: 6 additions & 2 deletions google_tag.install
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/

use Drupal\Core\StreamWrapper\PublicStream;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Url;

/**
* Implements hook_requirements().
Expand All @@ -20,7 +22,7 @@ function google_tag_requirements($phase) {
// 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'))),
'description' => t('Configure this integration module on its <a href=":url">settings page</a>.', array(':url' => Url::fromRoute('google_tag.settings_form')->toString())),
'severity' => REQUIREMENT_WARNING,
'value' => t('Not configured'),
);
Expand All @@ -29,8 +31,10 @@ function google_tag_requirements($phase) {
if ($phase == 'runtime' || $phase == 'install') {
// Adapted from system_requirements().
$directory = PublicStream::basePath() . '/js';
/** @var \Drupal\Core\File\FileSystemInterface $fileSystem */
$fileSystem = \Drupal::service('file_system');
if (!is_dir($directory) || !is_writable($directory)) {
file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
$fileSystem->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
}
$is_writable = is_writable($directory);
$is_directory = is_dir($directory);
Expand Down
13 changes: 10 additions & 3 deletions google_tag.module
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

use Drupal\Component\Utility\Unicode;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Messenger\MessengerInterface;

/**
* Default for matching all items except listed.
Expand Down Expand Up @@ -293,9 +295,11 @@ function google_tag_save_snippets() {
$saved = FALSE; $unsaved = FALSE;
$dir = _google_tag_get_js_dir();
$snippets = google_tag_snippets();
/** @var \Drupal\Core\File\FileSystemInterface $fileSystem */
$fileSystem = \Drupal::service('file_system');
foreach ($snippets as $type => $snippet) {
if ($dir_exists = file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
$path = file_unmanaged_save_data($snippet, "{$dir}/google_tag.{$type}.js", FILE_EXISTS_REPLACE);
if ($dir_exists = $fileSystem->prepareDirectory($dir, FileSystemInterface::CREATE_DIRECTORY)) {
$path = $fileSystem->saveData($snippet, "{$dir}/google_tag.{$type}.js", FileSystemInterface::EXISTS_REPLACE);
}
if ($dir_exists === TRUE && $path !== FALSE) {
$saved = TRUE;
Expand All @@ -306,7 +310,10 @@ function google_tag_save_snippets() {

}
if ($unsaved) {
drupal_set_message(t('An error occurred saving one or more snippet files. Please try again or contact the site administrator if it persists.'));
\Drupal::messenger()->addMessage(
t('An error occurred saving one or more snippet files. Please try again or contact the site administrator if it persists.'),
MessengerInterface::TYPE_STATUS
);
}
if ($saved) {
\Drupal::service('asset.js.collection_optimizer')->deleteAll();
Expand Down