Reputation: 577
I created a Sonata Admin-Class which I also added a customized Batch-Action:
protected function configureBatchActions(array $actions): array
{
$actions = parent::configureBatchActions($actions);
$actions['compareConfig'] = [
'ask_confirmation' => false,
'controller' => 'app.config_compare_controller::batchCompareConfigAction'
];
return $actions;
}
The service-definition (services.yaml):
app.config_compare_controller:
class: App\Controller\DatabasesCompareController
arguments: [ '@service_container' ]
calls:
- [ setContainer, [ '@service_container' ] ]
Controller (DatabasesCompareController):
public function batchCompareConfigAction(ProxyQueryInterface $query, AdminInterface $admin): ?Response {
...
dump($this->container->has('twig')); // => false
return $this->render('Admin/Databases/config_compare.html.twig', [
'content' => $content
]);
Due to the fact, that in another controller twig renders fine the following error-message confuses me:
You cannot use the "renderView" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle" (in vendor/symfony/framework-bundle/Controller/AbstractController.php)
Symfony: 6.0.11 Sonata-Admin: 4.17.0
What can I do to render my output?
Upvotes: 0
Views: 511
Reputation: 577
I solved it myself: You have to add the twig-Enviroment as an argument.
app.config_compare_controller:
class: App\Controller\DatabasesCompareController
arguments: [ '@twig' ]
calls:
- [ setContainer, [ '@service_container' ] ]
Upvotes: 0