Skip to content

Commit

Permalink
Minor code simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed Apr 11, 2015
1 parent 4958822 commit 09a5e43
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,14 @@ protected function editAction()
return $this->ajaxEdit();
}

if (!$item = $this->em->getRepository($this->entity['class'])->find($this->request->query->get('id'))) {
throw $this->createNotFoundException(sprintf('Unable to find entity (%s #%d).', $this->entity['name'], $this->request->query->get('id')));
$id = $this->request->query->get('id');
if (!$item = $this->em->getRepository($this->entity['class'])->find($id)) {
throw $this->createNotFoundException(sprintf('Unable to find entity (%s #%d).', $this->entity['name'], $id));
}

$fields = $this->entity['edit']['fields'];
$editForm = $this->createEditForm($item, $fields);
$deleteForm = $this->createDeleteForm($this->entity['name'], $this->request->query->get('id'));
$deleteForm = $this->createDeleteForm($this->entity['name'], $id);

$editForm->handleRequest($this->request);
if ($editForm->isValid()) {
Expand All @@ -195,12 +196,13 @@ protected function editAction()
*/
protected function showAction()
{
if (!$item = $this->em->getRepository($this->entity['class'])->find($this->request->query->get('id'))) {
throw $this->createNotFoundException(sprintf('Unable to find entity (%s #%d).', $this->entity['name'], $this->request->query->get('id')));
$id = $this->request->query->get('id');
if (!$item = $this->em->getRepository($this->entity['class'])->find($id)) {
throw $this->createNotFoundException(sprintf('Unable to find entity (%s #%d).', $this->entity['name'], $id));
}

$fields = $this->entity['show']['fields'];
$deleteForm = $this->createDeleteForm($this->entity['name'], $this->request->query->get('id'));
$deleteForm = $this->createDeleteForm($this->entity['name'], $id);

return $this->render('@EasyAdmin/show.html.twig', array(
'item' => $item,
Expand Down Expand Up @@ -252,11 +254,12 @@ protected function deleteAction()
return $this->redirect($this->generateUrl('admin', array('action' => 'list', 'view' => 'list', 'entity' => $this->entity['name'])));
}

$form = $this->createDeleteForm($this->entity['name'], $this->request->query->get('id'));
$id = $this->request->query->get('id');
$form = $this->createDeleteForm($this->entity['name'], $id);
$form->handleRequest($this->request);

if ($form->isValid()) {
if (!$entity = $this->em->getRepository($this->entity['class'])->find($this->request->query->get('id'))) {
if (!$entity = $this->em->getRepository($this->entity['class'])->find($id)) {
throw $this->createNotFoundException('The entity to be delete does not exist.');
}

Expand Down

0 comments on commit 09a5e43

Please sign in to comment.