You are here

public function ConfigSnapshotStorage::deleteAll in Config Snapshot 8

Deletes configuration objects whose names start with a given prefix.

Given the following configuration object names:

  • node.type.article
  • node.type.page

Passing the prefix 'node.type.' will delete the above configuration objects.

Parameters

string $prefix: (optional) The prefix to search for. If omitted, all configuration objects that exist will be deleted.

Return value

bool TRUE on success, FALSE otherwise.

Overrides StorageInterface::deleteAll

File

src/ConfigSnapshotStorage.php, line 209

Class

ConfigSnapshotStorage
Provides a configuration storage saved as simple configuration.

Namespace

Drupal\config_snapshot

Code

public function deleteAll($prefix = '') {
  $original_items = $items = $this->configSnapshot
    ->getItems();
  $collection = $this
    ->getCollectionName();
  $collection_items = array_filter($items, function ($item) use ($collection) {
    return $item['collection'] === $collection;
  });
  if ($prefix === '') {
    $items = array_diff_key($items, $collection_items);
  }
  else {
    foreach (array_keys($collection_items) as $key) {
      if (strpos($items[$key]['name'], $prefix) === 0) {
        unset($items[$key]);
      }
    }
  }

  // Determine if any items have changed.
  if ($items !== $original_items) {
    $this->configSnapshot
      ->setItems($items)
      ->save();
    return TRUE;
  }
  return FALSE;
}