You are here

public function GTMContainerManager::saveSnippets in GoogleTagManager 7.2

Saves JS snippet files based on current settings.

Parameters

GTMContainer $container: The container configuration entity.

Return value

bool Whether the files were saved.

Overrides ContainerManagerInterface::saveSnippets

1 call to GTMContainerManager::saveSnippets()
GTMContainerManager::createAssets in includes/entity/manager.inc
Prepares directory for and saves snippet files for a container.

File

includes/entity/manager.inc, line 52

Class

GTMContainerManager
Defines the Google tag container manager.

Code

public function saveSnippets($container) {

  // Save the altered snippets after hook_google_tag_snippets_alter().
  $result = TRUE;
  $snippets = $container
    ->snippets();
  foreach ($snippets as $type => $snippet) {
    $uri = $container
      ->snippetURI($type);
    $path = file_unmanaged_save_data($snippet, $uri, FILE_EXISTS_REPLACE);
    $result = !$path ? FALSE : $result;
  }
  $args = array(
    '@count' => count($snippets),
    '%container' => $container
      ->get('label'),
  );
  if (!$result) {
    $message = 'An error occurred saving @count snippet files for %container container. Contact the site administrator if this persists.';
    $this
      ->displayMessage($message, $args, 'error');
    watchdog('google_tag', $message, $args, WATCHDOG_ERROR);
  }
  else {
    $message = 'Created @count snippet files for %container container based on configuration.';
    $this
      ->displayMessage($message, $args);

    // Reset the URL query argument so browsers reload snippet files.
    _drupal_flush_css_js();
  }
  return $result;
}