public function edit(Request $request, $namespace, $file)
{
$file = $this->filesystem()->getFile("{$namespace}://{$file}");
if (!$file->authorized()) {
$this->flashes()->error(Trans::__('general.phrase.access-denied-permissions-edit-file', ['%s' => $file->getPath()]));
return $this->redirectToRoute('dashboard');
}
try {
$contents = $file->read();
} catch (FileNotFoundException $e) {
$this->flashes()->error(Trans::__('general.phrase.file-not-exist', ['%s' => $file->getPath()]));
return $this->redirectToRoute('dashboard');
} catch (IOException $e) {
$this->flashes()->error(Trans::__('general.phrase.file-not-readable', ['%s' => $file->getPath()]));
return $this->redirectToRoute('dashboard');
}
/** @var Form $form */
$form = $this->createFormBuilder(FormType::class, compact('contents'))->add('contents', TextareaType::class)->getForm();
// Handle the POST and check if it's valid.
$form->handleRequest($request);
if ($form->isSubmitted()) {
return $this->handleEdit($form, $file);
}
$context = ['form' => $form->createView(), 'file' => $file, 'write_allowed' => true, 'related' => $this->getRelatedFiles($file), 'datechanged' => $file->getCarbon()->toIso8601String(), 'codeMirrorPlugins' => $this->getCodeMirrorPlugins($file)];
return $this->render('@bolt/editfile/editfile.twig', $context);
}