function CheckpointStorage::listAll

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Config/Checkpoint/CheckpointStorage.php \Drupal\Core\Config\Checkpoint\CheckpointStorage::listAll()
  2. main core/lib/Drupal/Core/Config/Checkpoint/CheckpointStorage.php \Drupal\Core\Config\Checkpoint\CheckpointStorage::listAll()

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

core/lib/Drupal/Core/Config/Checkpoint/CheckpointStorage.php, line 171

Class

CheckpointStorage
Provides a config storage that can make checkpoints.

Namespace

Drupal\Core\Config\Checkpoint

Code

public function listAll($prefix = '') {
  if (count($this->checkpoints) === 0) {
    throw new NoCheckpointsException();
  }
  $names = $new_configuration = [];
  foreach ($this->getCheckpointsToReadFrom() as $checkpoint) {
    $checkpoint_names = array_keys(array_filter($this->getKeyValue($checkpoint->id, $this->collection)
      ->getAll(), function (mixed $value, string $name) use (&$new_configuration, $prefix) {
      if ($name === static::CONFIG_COLLECTION_KEY) {
        return FALSE;
      }
      // Remove any that don't start with the prefix.
      if ($prefix !== '' && !str_starts_with($name, $prefix)) {
        return FALSE;
      }
      // We've determined in a previous checkpoint that the configuration did
      // not exist.
      if (in_array($name, $new_configuration, TRUE)) {
        return FALSE;
      }
      // If the value is FALSE then the configuration was created after the
      // checkpoint.
      if ($value === FALSE) {
        $new_configuration[] = $name;
        return FALSE;
      }
      return TRUE;
    }, ARRAY_FILTER_USE_BOTH));
    $names = array_merge($names, $checkpoint_names);
  }
  // Remove any names that did not exist prior to the checkpoint.
  $active_names = array_diff($this->activeStorage
    ->listAll($prefix), $new_configuration);
  $names = array_unique(array_merge($names, $active_names));
  sort($names);
  return $names;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.