protected FileStorage::getAllCollectionNamesHelper($directory)
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:
1 2 3 4 5 6 | 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.
File
- core/lib/Drupal/Core/Config/FileStorage.php, line 313
Class
- FileStorage
- Defines the file storage.
Namespace
Drupal\Core\Config
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | protected function getAllCollectionNamesHelper( $directory ) { $collections = array (); $pattern = '/\.' . preg_quote( $this ->getFileExtension(), '/' ) . '$/' ; 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] !== '.' && preg_match( $pattern , $file )) { $collections [] = $collection ; break ; } } } } return $collections ; } |
Please login to continue.