public function edit(Request $request, $namespace, $file)
    {
        /** @var File $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');
        }

        $data = compact('contents');
        $options = [
            'write_allowed'        => true,
            'contents_allow_empty' => $file->getExtension() !== 'yml' ?: false,
            'contents_constraints' => $file->getExtension() === 'yml' ? [new Constraints\Yaml()] : [],
        ];
        /** @var Form $form */
        $form = $this->createFormBuilder(FileEditType::class, $data, $options)
            ->getForm()
        ;

        // Handle the POST and check if it's valid.
        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid() && $form->get('save')->isClicked()) {
            return $this->handleEdit($form, $file);
        }
        if ($form->isSubmitted() && !$form->isValid()) {
            return $this->json([
                'ok'  => false,
                'msg' => Trans::__('page.file-management.message.save-failed-invalid-form', ['%s' => $file->getPath()]),
            ]);
        }

        $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);
    }