You are here

public function ContainerManager::deleteAllAssets in GoogleTagManager 8

Deletes snippet files for all containers.

Return value

bool Whether the files were deleted.

Overrides ContainerManagerInterface::deleteAllAssets

File

src/Entity/ContainerManager.php, line 238

Class

ContainerManager
Defines the Google tag container manager.

Namespace

Drupal\google_tag\Entity

Code

public function deleteAllAssets() {
  if ($this->config
    ->get('flush_snippets')) {
    $directory = $this->config
      ->get('uri');
    if (!empty($directory)) {

      // Remove any stale files (e.g. module update or machine name change).
      return $this->fileSystem
        ->deleteRecursive($directory . '/google_tag');
    }
  }
  $ids = $this
    ->loadContainerIDs();
  if (!$ids) {
    return TRUE;
  }

  // Delete snippet files for enabled containers.
  $containers = $this->entityTypeManager
    ->getStorage('google_tag_container')
    ->loadMultiple($ids);
  $result = TRUE;
  foreach ($containers as $container) {
    $result = !$this
      ->deleteAssets($container) ? FALSE : $result;
  }
  return $result;
}