private function handleEdit(FormInterface $form, FileInterface $file)
    {
        $data = $form->getData();
        $contents = Input::cleanPostedData($data['contents']) . "\n";
        // Remove ^M and \r characters from the file.
        $contents = str_ireplace("\x0D", '', $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(),
        ]);
    }