Skip to content

Commit

Permalink
Avoid deprecated method
Browse files Browse the repository at this point in the history
We were calling a method we deprecated ourselves. I introduced a new
method, private this time, so that we can get the request.
  • Loading branch information
greg0ire committed Feb 4, 2017
1 parent 3c66861 commit bb10744
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions Controller/CoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function dashboardAction()
'blocks' => $blocks,
);

if (!$this->getRequest()->isXmlHttpRequest()) {
if (!$this->getCurrentRequest()->isXmlHttpRequest()) {
$parameters['breadcrumbs_builder'] = $this->get('sonata.admin.breadcrumbs_builder');
}

Expand Down Expand Up @@ -125,16 +125,13 @@ public function searchAction(Request $request)
*/
public function getRequest()
{
@trigger_error('The '.__METHOD__.' method is deprecated since 3.0 and will be removed in 4.0.'.
@trigger_error(
'The '.__METHOD__.' method is deprecated since 3.0 and will be removed in 4.0.'.
' Inject the Symfony\Component\HttpFoundation\Request into the actions instead.',
E_USER_DEPRECATED
);

if ($this->container->has('request_stack')) {
return $this->container->get('request_stack')->getCurrentRequest();
}

return $this->container->get('request');
return $this->getCurrentRequest();
}

/**
Expand All @@ -158,10 +155,25 @@ protected function getSearchHandler()
*/
protected function getBaseTemplate()
{
if ($this->getRequest()->isXmlHttpRequest()) {
if ($this->getCurrentRequest()->isXmlHttpRequest()) {
return $this->getAdminPool()->getTemplate('ajax');
}

return $this->getAdminPool()->getTemplate('layout');
}

/**
* Get the request object from the container.
*
* @return Request
*/
private function getCurrentRequest()
{
// NEXT_MAJOR: simplify this when dropping sf < 2.4
if ($this->container->has('request_stack')) {
return $this->container->get('request_stack')->getCurrentRequest();
}

return $this->container->get('request');
}
}

0 comments on commit bb10744

Please sign in to comment.