1
0
mirror of https://gitnet.fr/deblan/gist.git synced 2021-08-14 08:30:49 +02:00

Fix form validation

This commit is contained in:
Simon Vieille 2017-06-19 23:55:50 +02:00
parent 834faedc1f
commit bc67a2ce1c

View File

@ -8,6 +8,7 @@ use Gist\Form\CloneGistForm;
use Gist\Model\Gist;
use GitWrapper\GitException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Form\FormError;
/**
* Class EditController.
@ -37,9 +38,19 @@ class EditController extends Controller
if ($request->isMethod('post')) {
$form->submit($request);
$data = $form->getData();
if (empty($form->getData()['content']) && !$request->files->has('file')) {
$form->get('content')->addError(new FormError($app['translator']->trans('form.error.not_blank')));
} elseif (empty($form->getData()['content']) && $request->files->has('file')) {
if (count($form->get('file')->getErrors()) === 0) {
$data['content'] = file_get_contents($form->get('file')->getData()->getPathName());
unset($data['file']);
}
}
if ($form->isValid()) {
$gist = $app['gist']->create(new Gist(), $form->getData(), $this->getUser());
$gist = $app['gist']->create(new Gist(), $data, $this->getUser());
}
}