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

handleEdit() private method

Handle a file edit POST.
private handleEdit ( Symfony\Component\Form\FormInterface $form, Bolt\Filesystem\Handler\FileInterface $file ) : Symfony\Component\HttpFoundation\JsonResponse
$form Symfony\Component\Form\FormInterface
$file Bolt\Filesystem\Handler\FileInterface
return Symfony\Component\HttpFoundation\JsonResponse
    private function handleEdit(FormInterface $form, FileInterface $file)
    {
        if (!$form->isValid()) {
            return $this->json(['ok' => false, 'msg' => Trans::__('page.file-management.message.save-failed-invalid-form', ['%s' => $file->getPath()])]);
        }
        $data = $form->getData();
        $contents = Input::cleanPostedData($data['contents']) . "\n";
        // Remove ^M and \r characters from the file.
        $contents = str_ireplace("\r", '', $contents);
        // Before trying to save a yaml file, check if it's valid.
        if ($file->getType() === 'yaml') {
            $yamlparser = new Parser();
            try {
                $yamlparser->parse($contents);
            } catch (ParseException $e) {
                return $this->json(['ok' => false, 'msg' => Trans::__('page.file-management.message.save-failed-colon', ['%s' => $file->getPath()]) . $e->getMessage()]);
            }
        }
        try {
            $file->update($contents);
        } catch (ExceptionInterface $e) {
            return $this->json(['ok' => false, 'msg' => Trans::__('page.file-management.message.save-failed-unknown', ['%s' => $file->getPath()])]);
        }
        return $this->json(['ok' => true, 'msg' => Trans::__('page.file-management.message.save-success', ['%s' => $file->getPath()]), 'datechanged' => $file->getCarbon()->toIso8601String()]);
    }