getAllFolders(); if (isset($folders[$name])) { return $folders[$name] . '/' . $name . '.' . $this->getFileExtension(); } // If any code in the early installer requests a configuration object that // does not exist anywhere as default config, then that must be mistake. throw new StorageException("Missing configuration file: $name"); } /** * {@inheritdoc} */ public function exists($name) { return array_key_exists($name, $this->getAllFolders()); } /** * Overrides Drupal\Core\Config\FileStorage::write(). * * @throws \Drupal\Core\Config\StorageException */ public function write($name, array $data) { throw new StorageException('Write operation is not allowed.'); } /** * Overrides Drupal\Core\Config\FileStorage::delete(). * * @throws \Drupal\Core\Config\StorageException */ public function delete($name) { throw new StorageException('Delete operation is not allowed.'); } /** * Overrides Drupal\Core\Config\FileStorage::rename(). * * @throws \Drupal\Core\Config\StorageException */ public function rename($name, $new_name) { throw new StorageException('Rename operation is not allowed.'); } /** * {@inheritdoc} */ public function listAll($prefix = '') { $names = array_keys($this->getAllFolders()); if (!$prefix) { return $names; } else { $return = array(); foreach ($names as $index => $name) { if (strpos($name, $prefix) === 0 ) { $return[$index] = $names[$index]; } } return $return; } } /** * Returns a map of all config object names and their folders. * * @return array * An array mapping config object names with directories. */ protected function getAllFolders() { if (!isset($this->folders)) { $this->folders = array(); $this->folders += $this->getCoreNames(); // Perform an ExtensionDiscovery scan as we cannot use drupal_get_path() // yet because the system module may not yet be enabled during install. // @todo Remove as part of https://www.drupal.org/node/2186491 $listing = new ExtensionDiscovery(\Drupal::root()); if ($profile = drupal_get_profile()) { $profile_list = $listing->scan('profile'); if (isset($profile_list[$profile])) { // Prime the drupal_get_filename() static cache with the profile info // file location so we can use drupal_get_path() on the active profile // during the module scan. // @todo Remove as part of https://www.drupal.org/node/2186491 drupal_get_filename('profile', $profile, $profile_list[$profile]->getPathname()); $this->folders += $this->getComponentNames(array($profile_list[$profile])); } } // @todo Remove as part of https://www.drupal.org/node/2186491 $this->folders += $this->getComponentNames($listing->scan('module')); $this->folders += $this->getComponentNames($listing->scan('theme')); } return $this->folders; } /** * Get all configuration names and folders for a list of modules or themes. * * @param \Drupal\Core\Extension\Extension[] $list * An associative array of Extension objects, keyed by extension name. * * @return array * Folders indexed by configuration name. */ public function getComponentNames(array $list) { $extension = '.' . $this->getFileExtension(); $pattern = '/' . preg_quote($extension, '/') . '$/'; $folders = array(); foreach ($list as $extension_object) { // We don't have to use ExtensionDiscovery here because our list of // extensions was already obtained through an ExtensionDiscovery scan. $directory = $this->getComponentFolder($extension_object); if (is_dir($directory)) { // glob() directly calls into libc glob(), which is not aware of PHP // stream wrappers. Same for \GlobIterator (which additionally requires // an absolute realpath() on Windows). // @see https://github.com/mikey179/vfsStream/issues/2 $files = scandir($directory); foreach ($files as $file) { if ($file[0] !== '.' && preg_match($pattern, $file)) { $folders[basename($file, $extension)] = $directory; } } } } return $folders; } /** * Get all configuration names and folders for Drupal core. * * @return array * Folders indexed by configuration name. */ public function getCoreNames() { $extension = '.' . $this->getFileExtension(); $pattern = '/' . preg_quote($extension, '/') . '$/'; $folders = array(); $directory = $this->getCoreFolder(); if (is_dir($directory)) { // glob() directly calls into libc glob(), which is not aware of PHP // stream wrappers. Same for \GlobIterator (which additionally requires an // absolute realpath() on Windows). // @see https://github.com/mikey179/vfsStream/issues/2 $files = scandir($directory); foreach ($files as $file) { if ($file[0] !== '.' && preg_match($pattern, $file)) { $folders[basename($file, $extension)] = $directory; } } } return $folders; } /** * Get folder inside each component that contains the files. * * @param \Drupal\Core\Extension\Extension $extension * The Extension object for the component. * * @return string * The configuration folder name for this component. */ protected function getComponentFolder(Extension $extension) { return $extension->getPath() . '/' . $this->getCollectionDirectory(); } /** * Get folder inside Drupal core that contains the files. * * @return string * The configuration folder name for core. */ protected function getCoreFolder() { return drupal_get_path('core', 'core') . '/' . $this->getCollectionDirectory(); } /** * Overrides Drupal\Core\Config\FileStorage::deleteAll(). * * @throws \Drupal\Core\Config\StorageException */ public function deleteAll($prefix = '') { throw new StorageException('Delete operation is not allowed.'); } /** * Resets the static cache. */ public function reset() { $this->folders = NULL; } }