public function manage(Request $request, $namespace, $path)
{
$directory = $this->filesystem()->getDir("{$namespace}://{$path}");
if (!$directory->authorized()) {
$this->flashes()->error(Trans::__('general.phrase.access-denied-permissions-view-file-directory', ['%s' => $directory->getPath()]));
return $this->redirectToRoute('dashboard');
}
$form = null;
if (!$request->query->has('CKEditor') && $this->isAllowed('files:uploads')) {
// Define the "Upload here" form.
$form = $this->createFormBuilder(FormType::class)->add('FileUpload', FileType::class, ['label' => false, 'multiple' => true, 'attr' => ['data-filename-placement' => 'inside', 'title' => Trans::__('general.phrase.select-file'), 'accept' => '.' . join(',.', $this->getOption('general/accept_file_types'))]])->getForm();
// Handle the upload.
$form->handleRequest($request);
if ($form->isSubmitted()) {
$this->handleUpload($form, $directory);
return $this->redirectToRoute('files', ['path' => $directory->getPath(), 'namespace' => $directory->getMountPoint()]);
}
}
$it = $directory->getContents();
$files = array_filter($it, function (HandlerInterface $handler) {
return $handler->isFile();
});
$directories = array_filter($it, function (HandlerInterface $handler) {
return $handler->isDir();
});
// Select the correct template to render this. If we've got 'CKEditor' in the title, it's a dialog
// from CKeditor to insert a file.
$template = $request->query->has('CKEditor') ? '@bolt/files_ck/files_ck.twig' : '@bolt/files/files.twig';
$context = ['directory' => $directory, 'files' => $files, 'directories' => $directories, 'form' => $form ? $form->createView() : false];
return $this->render($template, $context);
}