Bolt\Controller\Backend\FileManager::edit PHP Method

edit() public method

File editor.
public edit ( Request $request, string $namespace, string $file ) : Response
$request Symfony\Component\HttpFoundation\Request The Symfony Request
$namespace string The filesystem namespace
$file string The file path
return Symfony\Component\HttpFoundation\Response
    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);
    }