You are here

public function ConfigSnapshotStorage::listAll in Config Snapshot 8

Gets configuration object names starting with a given prefix.

Given the following configuration objects:

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

Passing the prefix 'node.type.' will return an array containing the above names.

Parameters

string $prefix: (optional) The prefix to search for. If omitted, all configuration object names that exist are returned.

Return value

array An array containing matching configuration object names.

Overrides StorageInterface::listAll

File

src/ConfigSnapshotStorage.php, line 183

Class

ConfigSnapshotStorage
Provides a configuration storage saved as simple configuration.

Namespace

Drupal\config_snapshot

Code

public function listAll($prefix = '') {
  $names = [];
  $items = $this->configSnapshot
    ->getItems();

  // Find the keys of the items in the current collection.
  $collection_keys = array_keys(array_column($items, 'collection'), $this->collection);
  if ($prefix === '') {
    $name_items = array_column($items, 'name');

    // Find all names in the current collection.
    $names = array_values(array_intersect_key($name_items, array_flip($collection_keys)));
  }
  else {
    foreach ($collection_keys as $key) {
      if (strpos($items[$key]['name'], $prefix) === 0) {
        $names[] = $items[$key]['name'];
      }
    }
  }
  return $names;
}