function FileExampleSubmitHandlerHelper::handleDirectoryCreate
Submission handler for directory creation.
We create a directory and set the proper permissions on it using FileSystemInterface::prepareDirectory().
File
-
modules/
file_example/ src/ FileExampleSubmitHandlerHelper.php, line 414
Class
- FileExampleSubmitHandlerHelper
- A submit handler helper class for the file_example module.
Namespace
Drupal\file_exampleCode
public function handleDirectoryCreate(array &$form, FormStateInterface $form_state) {
$form_values = $form_state->getValues();
$directory = $form_values['directory_name'];
// The options passed to FileSystemInterface::prepareDirectory() are a
// bitmask, so we can specify either
// FileSystemInterface::MODIFY_PERMISSIONS,
// FileSystemInterface::CREATE_DIRECTORY, or both.
// FileSystemInterface::MODIFY_PERMISSIONS will set the permissions of the
// directory by default to 0755, or to the value of the variable
// 'file_chmod_directory'.
if (!$this->fileSystem
->prepareDirectory($directory, FileSystemInterface::MODIFY_PERMISSIONS | FileSystemInterface::CREATE_DIRECTORY)) {
$this->messenger
->addError($this->t('Failed to create %directory.', [
'%directory' => $directory,
]));
}
else {
$this->messenger
->addMessage($this->t('Directory %directory is ready for use.', [
'%directory' => $directory,
]));
$this->stateHelper
->setDefaultDirectory($directory);
}
}