I need to create signle global configuration page without list view, just single page with number of inputs like:
something that doesn't require to go through record listing, edit, save and return to list etc.
Do i need to create new controller with form and my own crud? Or is there a way to nicely connect/override sonata admin with that kind of panel?
I'm using:
EDIT
Following answer of pulzarraider and some more search i ended up with overriding listAction of CRUD controller.
In details, first created service definition (YML):
services:
stack.admin.global_administration:
class: Stack\Bundle\SiteBundle\Admin\GlobalConfigurationAdmin
tags:
- name: sonata.admin
manager_type: orm
group: Administration
label: Global Configuration
arguments:
- ~
- ~
- StackSiteBundle:GlobalConfiguration
Then created Admin class for this specific action:
<?php
namespace stack\Bundle\SiteBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Route\RouteCollection;
class GlobalConfigurationAdmin extends Admin
{
protected $baseRouteName = 'global-configuration';
protected $baseRoutePattern = 'global-admin';
protected function configureRoutes(RouteCollection $collection)
{
// notice removal of create action!
$collection->remove('create');
}
}
?>
And finally CRUD controller to display custom form instead of default entity list action:
<?php
namespace Stack\Bundle\SiteBundle\Controller;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
use Symfony\Component\HttpFoundation\Request;
class GlobalConfigurationController extends Controller
{
public function listAction()
{
if (false === $this->admin->isGranted('LIST')) {
throw new AccessDeniedException();
}
// custom code here...
return $this->render('StackSiteBundle:Administration:configuration-view.html.twig', array(
'action' => 'list',
'csrf_token' => $this->getCsrfToken('sonata.batch')
));
}
}
?>
Thanks for help with this one!
Yes, it`s possible in Sonata Admin by overloading default CRUD controller.
You must create custom controller and overload editAction
.
In editAction you can create standard Symfony form, process the data from user and save it anywhere you want.