Skip to content

Commit

Permalink
Merge 4bfc0c7 into ea2e4f6
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Nov 28, 2017
2 parents ea2e4f6 + 4bfc0c7 commit 03d6f9c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
42 changes: 23 additions & 19 deletions src/Controller/CRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,7 @@ public function batchActionDelete(ProxyQueryInterface $query)
);
}

return new RedirectResponse($this->admin->generateUrl(
'list',
['filter' => $this->admin->getFilterParameters()]
));
return $this->redirectToList();
}

/**
Expand Down Expand Up @@ -474,12 +471,7 @@ public function batchAction()
$this->trans($nonRelevantMessage, [], 'SonataAdminBundle')
);

return new RedirectResponse(
$this->admin->generateUrl(
'list',
['filter' => $this->admin->getFilterParameters()]
)
);
return $this->redirectToList();
}

$askConfirmation = isset($batchActions[$action]['ask_confirmation']) ?
Expand Down Expand Up @@ -527,11 +519,7 @@ public function batchAction()
$this->trans('flash_batch_no_elements_processed', [], 'SonataAdminBundle')
);

return new RedirectResponse(
$this->admin->generateUrl('list', [
'filter' => $this->admin->getFilterParameters(),
])
);
return $this->redirectToList();
}

return call_user_func([$this, $finalAction], $query, $request);
Expand Down Expand Up @@ -1177,10 +1165,10 @@ protected function redirectTo($object)
$url = false;

if (null !== $request->get('btn_update_and_list')) {
$url = $this->admin->generateUrl('list');
return $this->redirectToList();
}
if (null !== $request->get('btn_create_and_list')) {
$url = $this->admin->generateUrl('list');
return $this->redirectToList();
}

if (null !== $request->get('btn_create_and_create')) {
Expand All @@ -1192,7 +1180,7 @@ protected function redirectTo($object)
}

if ('DELETE' === $this->getRestMethod()) {
$url = $this->admin->generateUrl('list');
return $this->redirectToList();
}

if (!$url) {
Expand All @@ -1206,12 +1194,28 @@ protected function redirectTo($object)
}

if (!$url) {
$url = $this->admin->generateUrl('list');
return $this->redirectToList();
}

return new RedirectResponse($url);
}

/**
* Redirects the user to the list view.
*
* @return RedirectResponse
*/
final protected function redirectToList()
{
$parameters = [];

if ($filter = $this->admin->getFilterParameters()) {
$parameters['filter'] = $filter;
}

return $this->redirect($this->admin->generateUrl('list', $parameters));
}

/**
* Returns true if the preview is requested to be shown.
*
Expand Down
12 changes: 6 additions & 6 deletions tests/Controller/CRUDControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3386,7 +3386,7 @@ public function testBatchActionWithoutConfirmation()

$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
$this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
$this->assertSame('list?', $result->getTargetUrl());
$this->assertSame('list', $result->getTargetUrl());
}

/**
Expand Down Expand Up @@ -3444,7 +3444,7 @@ public function testBatchActionWithoutConfirmation2()

$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
$this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
$this->assertSame('list?', $result->getTargetUrl());
$this->assertSame('list', $result->getTargetUrl());
}

/**
Expand Down Expand Up @@ -3534,7 +3534,7 @@ public function testBatchActionNonRelevantAction()

$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
$this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
$this->assertSame('list?', $result->getTargetUrl());
$this->assertSame('list', $result->getTargetUrl());
}

/**
Expand Down Expand Up @@ -3570,7 +3570,7 @@ public function testBatchActionNonRelevantAction2()

$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
$this->assertSame(['flash_foo_error'], $this->session->getFlashBag()->get('sonata_flash_info'));
$this->assertSame('list?', $result->getTargetUrl());
$this->assertSame('list', $result->getTargetUrl());
}

/**
Expand Down Expand Up @@ -3603,7 +3603,7 @@ public function testBatchActionNoItems()

$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
$this->assertSame(['flash_batch_empty'], $this->session->getFlashBag()->get('sonata_flash_info'));
$this->assertSame('list?', $result->getTargetUrl());
$this->assertSame('list', $result->getTargetUrl());
}

/**
Expand Down Expand Up @@ -3709,7 +3709,7 @@ public function testBatchActionWithRequesData()

$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $result);
$this->assertSame(['flash_batch_delete_success'], $this->session->getFlashBag()->get('sonata_flash_success'));
$this->assertSame('list?', $result->getTargetUrl());
$this->assertSame('list', $result->getTargetUrl());
$this->assertSame('bar', $this->request->request->get('foo'));
}

Expand Down

0 comments on commit 03d6f9c

Please sign in to comment.