Skip to content

Commit

Permalink
Upgrade to symfony 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
vieilles committed Nov 27, 2013
1 parent 58b9557 commit e1271ab
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 66 deletions.
18 changes: 9 additions & 9 deletions Crud/Crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ public function __construct(

// Entity
list($bundle, $entity) = $this->parseShortcutNotation($entity);
$this->_entityClass = $this->_doctrine->getEntityNamespace($bundle).'\\'.$entity;
$this->_entityClass = $this->_doctrine->getAliasNamespace($bundle).'\\'.$entity;

// EntityType
list($bundle, $entityType) = $this->parseShortcutNotation($entityType);
$entityTypeClass = $this->_doctrine->getEntityNamespace($bundle);
$entityTypeClass = $this->_doctrine->getAliasNamespace($bundle);
$parts = explode('\\', $entityTypeClass);
array_pop($parts);
$this->_entityTypeClass = implode('\\', $parts).'\\Form\\'.$entityType;
Expand Down Expand Up @@ -215,11 +215,11 @@ protected function prepareListView()
$this->_datagrid->addAction(new Action($this->trans('Delete'), $this->_request->get('_route'), array_merge($this->getConfig('addToURL'), array($this->getConfig('viewVar') => 'delete')), $this->trans('Confirm delete ?'), '#icon-remove'), 'delete');
}

if ($this->_session->hasFlash('crud_success')) {
$this->_datagrid->addNotification(new Notification($this->_session->getFlash('crud_success'), 'success'));
foreach ($this->_session->getFlashBag()->get('crud_success') as $notification) {
$this->_datagrid->addNotification(new Notification($notification, 'success'));
}
if ($this->_session->hasFlash('crud_error')) {
$this->_datagrid->addNotification(new Notification($this->_session->getFlash('crud_error'), 'error'));
foreach ($this->_session->getFlashBag()->get('crud_error') as $notification) {
$this->_datagrid->addNotification(new Notification($notification, 'error'));
}
}

Expand All @@ -234,7 +234,7 @@ protected function addAction()
$this->_formDatas = $this->_form->create(new $this->_entityTypeClass, new $this->_entityClass, array(), 'redirect', $options);

if ($this->_formDatas instanceof Response) {
$this->_session->setFlash('crud_success', $this->trans('Creation successful'));
$this->_session->getFlashBag()->add('crud_success', $this->trans('Creation successful'));
return $this->_formDatas;
}
return array('crud' => $this);
Expand All @@ -246,7 +246,7 @@ protected function editAction($id)
$this->_formDatas = $this->_form->edit(new $this->_entityTypeClass, array($this->_entity, $id), array(), 'redirect', $options);

if ($this->_formDatas instanceof Response) {
$this->_session->setFlash('crud_success', $this->trans('Edition successful'));
$this->_session->getFlashBag()->add('crud_success', $this->trans('Edition successful'));
return $this->_formDatas;
}
return array('crud' => $this);
Expand All @@ -258,7 +258,7 @@ protected function deleteAction($id)
$this->_formDatas = $this->_form->delete(array($this->_entity, $id), 'redirect', $options);

if ($this->_formDatas instanceof Response) {
$this->_session->setFlash('crud_success', $this->trans('Delete successful'));
$this->_session->getFlashBag()->add('crud_success', $this->trans('Delete successful'));
}
return $this->_formDatas;
}
Expand Down
109 changes: 53 additions & 56 deletions Service/FormService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,38 @@ public function create($type, $data, array $options = array(), $responseType = '
$responseOptions = array_merge($this->defaultResponseOptions, $responseOptions);
$message = null;

$em = $this->_doctrine->getEntityManager();
$em = $this->_doctrine->getManager();
$form = $this->_formFactory->create($type, $data, $options);
$request = $this->_request;

if ($request->getMethod() === 'POST') {
$form->bindRequest($request);
if ($form->isValid()) {
$em->persist($data);
$em->flush();

switch ($responseType) {
case 'json':
$message = array(
'success' => true,
'message' => $responseOptions['success']
);
return new Response(json_encode($message), $responseOptions['status'], array('Content-type' => 'application/json'));
break;

case 'redirect':
return new RedirectResponse($responseOptions['url'], $responseOptions['redirectStatus']);
break;

default:
case 'html':
$message = $responseOptions['success'];
break;
}
}
else {
$message = $responseOptions['error'];
$form->handleRequest($request);
if ($form->isValid()) {
$em->persist($data);
$em->flush();

switch ($responseType) {
case 'json':
$message = array(
'success' => true,
'message' => $responseOptions['success']
);
return new Response(json_encode($message), $responseOptions['status'], array('Content-type' => 'application/json'));
break;

case 'redirect':
return new RedirectResponse($responseOptions['url'], $responseOptions['redirectStatus']);
break;

default:
case 'html':
$message = $responseOptions['success'];
break;
}
}
else {
$message = $responseOptions['error'];
}

return array('form' => $form->createView(), 'item' => $data, 'action' => 'create', 'message' => $message);
}

Expand All @@ -82,7 +81,7 @@ public function edit($type, $data, array $options = array(), $responseType = 'ht
$responseOptions = array_merge($this->defaultResponseOptions, $responseOptions);
$message = null;

$em = $this->_doctrine->getEntityManager();
$em = $this->_doctrine->getManager();
if (is_array($data)) {
$data = $em->getRepository($data[0])->find($data[1]);
}
Expand All @@ -108,34 +107,32 @@ public function edit($type, $data, array $options = array(), $responseType = 'ht
$form = $this->_formFactory->create($type, $data, $options);
$request = $this->_request;

if ($request->getMethod() === 'POST') {
$form->bindRequest($request);
if ($form->isValid()) {
$em->flush();

switch ($responseType) {
case 'json':
$message = array(
'success' => true,
'message' => $responseOptions['success']
);
return new Response(json_encode($message), 200, array('Content-type' => 'application/json'));
break;

case 'redirect':
return new RedirectResponse($responseOptions['url'], $responseOptions['redirectStatus']);
break;

default:
case 'html':
$message = $responseOptions['success'];
break;
}
}
else {
$message = $responseOptions['error'];
$form->handleRequest($request);
if ($form->isValid()) {
$em->flush();

switch ($responseType) {
case 'json':
$message = array(
'success' => true,
'message' => $responseOptions['success']
);
return new Response(json_encode($message), 200, array('Content-type' => 'application/json'));
break;

case 'redirect':
return new RedirectResponse($responseOptions['url'], $responseOptions['redirectStatus']);
break;

default:
case 'html':
$message = $responseOptions['success'];
break;
}
}
else {
$message = $responseOptions['error'];
}

return array('form' => $form->createView(), 'item' => $data, 'action' => 'edit', 'message' => $message);
}
Expand All @@ -145,7 +142,7 @@ public function delete($data, $responseType = 'json', array $responseOptions = a
$responseOptions = array_merge($this->defaultResponseOptions, $responseOptions);
$message = null;

$em = $this->_doctrine->getEntityManager();
$em = $this->_doctrine->getManager();
if (is_array($data)) {
$data = $em->getRepository($data[0])->find($data[1]);
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"require": {
"symfony/framework-bundle": "2.*"
"symfony/framework-bundle": "~2.3"
},
"autoload": {
"psr-0": {
Expand Down

0 comments on commit e1271ab

Please sign in to comment.