protected function FileStorage::getAllCollectionNamesHelper in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Config/FileStorage.php \Drupal\Core\Config\FileStorage::getAllCollectionNamesHelper()
Helper function for getAllCollectionNames().
If the file storage has the following subdirectory structure: ./another_collection/one ./another_collection/two ./collection/sub/one ./collection/sub/two this function will return:
array(
'another_collection.one',
'another_collection.two',
'collection.sub.one',
'collection.sub.two',
);
Parameters
string $directory: The directory to check for sub directories. This allows this function to be used recursively to discover all the collections in the storage.
Return value
array A list of collection names contained within the provided directory.
1 call to FileStorage::getAllCollectionNamesHelper()
- FileStorage::getAllCollectionNames in core/
lib/ Drupal/ Core/ Config/ FileStorage.php - Gets the existing collections.
File
- core/
lib/ Drupal/ Core/ Config/ FileStorage.php, line 290 - Contains \Drupal\Core\Config\FileStorage.
Class
- FileStorage
- Defines the file storage.
Namespace
Drupal\Core\ConfigCode
protected function getAllCollectionNamesHelper($directory) {
$collections = array();
foreach (new \DirectoryIterator($directory) as $fileinfo) {
if ($fileinfo
->isDir() && !$fileinfo
->isDot()) {
$collection = $fileinfo
->getFilename();
// Recursively call getAllCollectionNamesHelper() to discover if there
// are subdirectories. Subdirectories represent a dotted collection
// name.
$sub_collections = $this
->getAllCollectionNamesHelper($directory . '/' . $collection);
if (!empty($sub_collections)) {
// Build up the collection name by concatenating the subdirectory
// names with the current directory name.
foreach ($sub_collections as $sub_collection) {
$collections[] = $collection . '.' . $sub_collection;
}
}
// Check that the collection is valid by searching it for configuration
// objects. A directory without any configuration objects is not a valid
// collection.
// @see \Drupal\Core\Config\FileStorage::listAll()
foreach (scandir($directory . '/' . $collection) as $file) {
if ($file[0] !== '.' && fnmatch('*.' . $this
->getFileExtension(), $file)) {
$collections[] = $collection;
break;
}
}
}
}
return $collections;
}