I want to activate the sonata admin search feature after the migration to of symfony to version 3.4.2. I found a problem in sonata block service:
An exception has been thrown during the rendering of a template ("The Request object has not been set").
this is sonata block configuration :
sonata_block.yml
sonata_block:
default_contexts: [cms]
blocks:
sonata.admin.block.admin_list:
contexts: [admin]
sonata.admin.block.search_result:
contexts: [admin]
sonata.block.service.text:
sonata.block.service.rss:
any solution please ?
The solution is to override the get request function because she throws an exception:
public function getRequest()
{
if (!$this->request) {
throw new \RuntimeException('The Request object has not been set');
}
return $this->request;
}
so I create a class that extends the abstract admin and make every class in my admin folder extends from it:
class MYAdmin extends AbstractAdmin
{
/**
* {@inheritdoc}
*/
public function getRequest()
{
if (!$this->request) {
return $this->request = $this->getConfigurationPool()->getContainer()->get('request_stack')->getCurrentRequest();
}
return $this->request;
}
}