|
@@ -11,69 +11,70 @@ Quick example
|
|
|
|
|
|
Defining an ``Admin`` class is pretty easy: simply define ``configure[Show|Form|List|Datagrid]Fields`` methods
|
|
Defining an ``Admin`` class is pretty easy: simply define ``configure[Show|Form|List|Datagrid]Fields`` methods
|
|
|
|
|
|
- <?php
|
|
|
|
- namespace Sonata\NewsBundle\Admin;
|
|
|
|
-
|
|
|
|
- use Sonata\AdminBundle\Admin\Admin;
|
|
|
|
- use Sonata\AdminBundle\Form\FormMapper;
|
|
|
|
- use Sonata\AdminBundle\Datagrid\DatagridMapper;
|
|
|
|
- use Sonata\AdminBundle\Datagrid\ListMapper;
|
|
|
|
- use Sonata\AdminBundle\Show\ShowMapper;
|
|
|
|
|
|
+``` php
|
|
|
|
+<?php
|
|
|
|
+namespace Sonata\NewsBundle\Admin;
|
|
|
|
+
|
|
|
|
+use Sonata\AdminBundle\Admin\Admin;
|
|
|
|
+use Sonata\AdminBundle\Form\FormMapper;
|
|
|
|
+use Sonata\AdminBundle\Datagrid\DatagridMapper;
|
|
|
|
+use Sonata\AdminBundle\Datagrid\ListMapper;
|
|
|
|
+use Sonata\AdminBundle\Show\ShowMapper;
|
|
|
|
+
|
|
|
|
+class PostAdmin extends Admin
|
|
|
|
+{
|
|
|
|
+ public function configureShowFields(ShowMapper $showMapper)
|
|
|
|
+ {
|
|
|
|
+ $showMapper
|
|
|
|
+ ->add('author')
|
|
|
|
+ ->add('enabled')
|
|
|
|
+ ->add('title')
|
|
|
|
+ ->add('abstract')
|
|
|
|
+ ->add('content')
|
|
|
|
+ ->add('tags')
|
|
|
|
+ ;
|
|
|
|
+ }
|
|
|
|
|
|
- class PostAdmin extends Admin
|
|
|
|
|
|
+ public function configureFormFields(FormMapper $formMapper)
|
|
{
|
|
{
|
|
- public function configureShowFields(ShowMapper $showMapper)
|
|
|
|
- {
|
|
|
|
- $showMapper
|
|
|
|
- ->add('author')
|
|
|
|
- ->add('enabled')
|
|
|
|
|
|
+ $formMapper
|
|
|
|
+ ->with('General')
|
|
|
|
+ ->add('enabled', null, array('required' => false))
|
|
|
|
+ ->add('author', 'sonata_type_model', array(), array('edit' => 'list'))
|
|
->add('title')
|
|
->add('title')
|
|
->add('abstract')
|
|
->add('abstract')
|
|
->add('content')
|
|
->add('content')
|
|
- ->add('tags')
|
|
|
|
- ;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public function configureFormFields(FormMapper $formMapper)
|
|
|
|
- {
|
|
|
|
- $formMapper
|
|
|
|
- ->with('General')
|
|
|
|
- ->add('enabled', null, array('required' => false))
|
|
|
|
- ->add('author', 'sonata_type_model', array(), array('edit' => 'list'))
|
|
|
|
- ->add('title')
|
|
|
|
- ->add('abstract')
|
|
|
|
- ->add('content')
|
|
|
|
- ->end()
|
|
|
|
- ->with('Tags')
|
|
|
|
- ->add('tags', 'sonata_type_model', array('expanded' => true))
|
|
|
|
- ->end()
|
|
|
|
- ->with('Options', array('collapsed' => true))
|
|
|
|
- ->add('commentsCloseAt')
|
|
|
|
- ->add('commentsEnabled', null, array('required' => false))
|
|
|
|
- ->end()
|
|
|
|
- ;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public function configureListFields(ListMapper $listMapper)
|
|
|
|
- {
|
|
|
|
- $listMapper
|
|
|
|
- ->addIdentifier('title')
|
|
|
|
- ->add('author')
|
|
|
|
- ->add('enabled')
|
|
|
|
- ->add('tags')
|
|
|
|
- ->add('commentsEnabled')
|
|
|
|
- ;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public function configureDatagridFilters(DatagridMapper $datagridMapper)
|
|
|
|
- {
|
|
|
|
- $datagridMapper
|
|
|
|
- ->add('title')
|
|
|
|
- ->add('enabled')
|
|
|
|
- ->add('tags', null, array('filter_field_options' => array('expanded' => true, 'multiple' => true)))
|
|
|
|
- }
|
|
|
|
|
|
+ ->end()
|
|
|
|
+ ->with('Tags')
|
|
|
|
+ ->add('tags', 'sonata_type_model', array('expanded' => true))
|
|
|
|
+ ->end()
|
|
|
|
+ ->with('Options', array('collapsed' => true))
|
|
|
|
+ ->add('commentsCloseAt')
|
|
|
|
+ ->add('commentsEnabled', null, array('required' => false))
|
|
|
|
+ ->end()
|
|
|
|
+ ;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function configureListFields(ListMapper $listMapper)
|
|
|
|
+ {
|
|
|
|
+ $listMapper
|
|
|
|
+ ->addIdentifier('title')
|
|
|
|
+ ->add('author')
|
|
|
|
+ ->add('enabled')
|
|
|
|
+ ->add('tags')
|
|
|
|
+ ->add('commentsEnabled')
|
|
|
|
+ ;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function configureDatagridFilters(DatagridMapper $datagridMapper)
|
|
|
|
+ {
|
|
|
|
+ $datagridMapper
|
|
|
|
+ ->add('title')
|
|
|
|
+ ->add('enabled')
|
|
|
|
+ ->add('tags', null, array('filter_field_options' => array('expanded' => true, 'multiple' => true)))
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+```
|
|
Screenshots : http://www.dropbox.com/gallery/581816/2/BaseApplicationBundle/preview?h=59b2e8
|
|
Screenshots : http://www.dropbox.com/gallery/581816/2/BaseApplicationBundle/preview?h=59b2e8
|
|
|
|
|
|
Of course, power users will be happy as an ``Admin`` class is very flexible as all dependencies are
|
|
Of course, power users will be happy as an ``Admin`` class is very flexible as all dependencies are
|