form improvement

using theme clone
This commit is contained in:
Kevin Papst
2016-11-13 22:19:18 +01:00
parent cc269d3142
commit aaa2fffa08
22 changed files with 411 additions and 60 deletions

View File

@@ -12,13 +12,15 @@
namespace TimesheetBundle\Controller\Admin;
use Pagerfanta\Pagerfanta;
use Symfony\Component\HttpFoundation\Request;
use TimesheetBundle\Entity\Project;
use TimesheetBundle\Entity\Timesheet;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use TimesheetBundle\Form\ProjectEditForm;
use TimesheetBundle\Repository\ProjectRepository;
/**
* Controller used to manage projects in the admin part of the site.
@@ -35,6 +37,9 @@ class ProjectController extends Controller
* @Route("/page/{page}", requirements={"page": "[1-9]\d*"}, name="admin_project_paginated")
* @Method("GET")
* @Cache(smaxage="10")
*
* @param $page
* @return \Symfony\Component\HttpFoundation\Response
*/
public function indexAction($page)
{
@@ -43,4 +48,72 @@ class ProjectController extends Controller
return $this->render('TimesheetBundle:admin:project.html.twig', ['entries' => $entries]);
}
/**
* @Route("/{id}/edit", name="admin_project_edit")
* @Method({"GET", "POST"})
*
* @param $id
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function editAction($id, Request $request)
{
$project = $this->getById($id);
$editForm = $this->createEditForm($project);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($project);
$entityManager->flush();
$this->addFlash('success', 'action.updated_successfully');
return $this->redirectToRoute(
'admin_project', ['id' => $project->getId()]
);
}
return $this->render(
'TimesheetBundle:admin:project_edit.html.twig',
[
'project' => $project,
'form' => $editForm->createView()
]
);
}
/**
* @param $id
* @return null|Project
*/
protected function getById($id)
{
/* @var $repo ProjectRepository */
$repo = $this->getDoctrine()->getRepository(Project::class);
$activity = $repo->getById($id);
if (null === $activity) {
throw new NotFoundHttpException('Project "'.$id.'" does not exist');
}
return $activity;
}
/**
* @param Project $project
* @return \Symfony\Component\Form\Form
*/
private function createEditForm(Project $project)
{
return $this->createForm(
ProjectEditForm::class,
$project,
[
'action' => $this->generateUrl('admin_project_edit', ['id' => $project->getId()]),
'method' => 'POST',
'currency' => $project->getCurrency()
]
);
}
}