function FileStorage::ensureStorage

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Config/FileStorage.php \Drupal\Core\Config\FileStorage::ensureStorage()
  2. 10 core/lib/Drupal/Core/Config/FileStorage.php \Drupal\Core\Config\FileStorage::ensureStorage()
  3. 11.x core/lib/Drupal/Core/Config/FileStorage.php \Drupal\Core\Config\FileStorage::ensureStorage()

Check if the directory exists and create it if not.

1 call to FileStorage::ensureStorage()
FileStorage::write in core/lib/Drupal/Core/Config/FileStorage.php
Writes configuration data to the storage.

File

core/lib/Drupal/Core/Config/FileStorage.php, line 78

Class

FileStorage
Defines the file storage.

Namespace

Drupal\Core\Config

Code

protected function ensureStorage() {
    $dir = $this->getCollectionDirectory();
    $success = $this->getFileSystem()
        ->prepareDirectory($dir, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
    // Only create .htaccess file in root directory.
    if ($dir == $this->directory) {
        $success = $success && FileSecurity::writeHtaccess($this->directory);
    }
    if (!$success) {
        throw new StorageException('Failed to create config directory ' . $dir);
    }
    return $this;
}

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