Prechádzať zdrojové kódy

Update documentation

Thomas Rabaix 13 rokov pred
rodič
commit
5eef7fdc3f

+ 16 - 13
Resources/doc/reference/advance.rst

@@ -1,19 +1,21 @@
 Advance
 =======
 
-By default services who are injected to the admin service are
-    method name         |    Service Id
----------------------------------------------------------------------
-    model_manager       |    sonata.admin.manager.%manager-type%
-    form_contractor     |    sonata.admin.builder.%manager-type%_form
-    show_builder        |    sonata.admin.builder.%manager-type%_show
-    list_builder        |    sonata.admin.builder.%manager-type%_list
-    datagrid_builder    |    sonata.admin.builder.%manager-type%_datagrid
-    translator          |    translator
-    configuration_pool  |    sonata.admin.pool
-    router              |    router
-    validator           |    validator
-    security_handler    |    sonata.admin.security.handler
+By default services who are injected to an admin instance are
+
+========================    =============================================
+    method name             Service Id
+========================    =============================================
+    model_manager           sonata.admin.manager.%manager-type%
+    form_contractor         sonata.admin.builder.%manager-type%_form
+    show_builder            sonata.admin.builder.%manager-type%_show
+    list_builder            sonata.admin.builder.%manager-type%_list
+    datagrid_builder        sonata.admin.builder.%manager-type%_datagrid
+    translator              translator
+    configuration_pool      sonata.admin.pool
+    router                  router
+    validator               validator
+    security_handler        sonata.admin.security.handler
 
 Note: %manager-type% is replace by the manager type (orm, odm...)
 
@@ -21,6 +23,7 @@ If you want to modify the service who are going to be injected, add the followin
 application's config file:
 
 .. code-block:: yaml
+
     # app/config/config.yml
     admins:
         sonata_admin: #method name, you can find the list in the table above

+ 23 - 22
Resources/doc/reference/conditional_validation.rst

@@ -12,30 +12,31 @@ object. The object can be use to check assertion against a model :
 
 .. code-block:: php
 
+    <?php
+    $errorElement
+        ->with('settings.url')
+            ->assertNotNull(array())
+            ->assertNotBlank()
+        ->end()
+        ->with('settings.title')
+            ->assertNotNull(array())
+            ->assertNotBlank()
+            ->assertMinLength(array('limit' => 50))
+            ->addViolation('ho yeah!')
+        ->end();
+
+    if (/* complex rules */) {
+        $errorElement->with('value')->addViolation('Fail to check the complex rules')->end()
+    }
+
+    /* conditional validation */
+    if ($this->getSubject()->getState() == Post::STATUS_ONLINE) {
         $errorElement
-            ->with('settings.url')
-                ->assertNotNull(array())
-                ->assertNotBlank()
-            ->end()
-            ->with('settings.title')
-                ->assertNotNull(array())
-                ->assertNotBlank()
-                ->assertMinLength(array('limit' => 50))
-                ->addViolation('ho yeah!')
+            ->with('enabled')
+                ->assertNotNull()
+                ->assertTrue()
             ->end();
-
-        if (/* complex rules */) {
-            $errorElement->with('value')->addViolation('Fail to check the complex rules')->end()
-        }
-
-        /* conditional validation */
-        if ($this->getSubject()->getState() == Post::STATUS_ONLINE) {
-            $errorElement
-                ->with('enabled')
-                    ->assertNotNull()
-                    ->assertTrue()
-                ->end();
-        }
+    }
 
 .. note::
 

+ 1 - 0
Resources/doc/reference/installation.rst

@@ -59,6 +59,7 @@ files:
 
 .. code-block:: php
 
+  <?php
   // app/autoload.php
   $loader->registerNamespaces(array(
       // ...

+ 1 - 1
Resources/doc/reference/update.rst

@@ -7,7 +7,7 @@ Update notes for early users
 * ListMapper now have an ``addIdentifier`` method
 * internal Sonata Form Types must be set as second argument of the FormMapper
 
-Example :
+.. code-block:: php
 
     <?php
     namespace Sonata\NewsBundle\Admin;

+ 122 - 87
Resources/doc/tutorial/creating_your_first_admin_class/defining_admin_class.rst

@@ -152,53 +152,6 @@ This interface will display too many fields as some of them are not relevant to
 a general overview. Next We'll see how to specify the fields we want to use and
 how we want to use them.
 
-Tweak the PostAdmin class
--------------------------
-
-You can specify which field you want displayed for each action (list, form and filter)
-
-.. code-block:: 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 Knp\Menu\MenuItem;
-
-    use Application\Sonata\NewsBundle\Entity\Comment;
-
-    class PostAdmin extends Admin
-    {
-       protected $list = array(
-           'title' => array('identifier' => true),
-           'slug',
-           'enabled',
-           'comments_enabled',
-       );
-
-       protected $form = array(
-           'enabled',
-           'title',
-           'abstract',
-           'content',
-           'tags' => array('form_field_options' => array('expanded' => true)),
-           'comments_enabled',
-           'comments_default_status'
-       );
-
-       protected $filter = array(
-           'title',
-           'enabled',
-           'tags' => array('filter_field_options' => array('expanded' => true, 'multiple' => true))
-       );
-     }
-
-Now the different CRUD interfaces will look nicer!
-
 So same goes for the TagAdmin and CommentAdmin class.
 
 Tweak the TagAdmin class
@@ -210,24 +163,63 @@ Tweak the TagAdmin class
     namespace Sonata\NewsBundle\Admin;
 
     use Sonata\AdminBundle\Admin\Admin;
+    use Sonata\AdminBundle\Datagrid\ListMapper;
+    use Sonata\AdminBundle\Datagrid\DatagridMapper;
+    use Sonata\AdminBundle\Validator\ErrorElement;
+    use Sonata\AdminBundle\Form\FormMapper;
 
     class TagAdmin extends Admin
     {
-        protected $list = array(
-            'name' => array('identifier' => true),
-            'slug',
-            'enabled',
-        );
-
-        protected $form = array(
-            'id',
-            'name',
-            'enabled'
-        );
-
-        protected $filter = array(
-            'name'
-        );
+        /**
+         * @param \Sonata\AdminBundle\Form\FormMapper $formMapper
+         * @return void
+         */
+        protected function configureFormFields(FormMapper $formMapper)
+        {
+            $formMapper
+                ->add('name')
+                ->add('enabled', null, array('required' => false))
+            ;
+        }
+
+        /**
+         * @param \Sonata\AdminBundle\Datagrid\DatagridMapper $datagridMapper
+         * @return void
+         */
+        protected function configureDatagridFilters(DatagridMapper $datagridMapper)
+        {
+            $datagridMapper
+                ->add('name')
+                ->add('posts')
+            ;
+        }
+
+        /**
+         * @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
+         * @return void
+         */
+        protected function configureListFields(ListMapper $listMapper)
+        {
+            $listMapper
+                ->addIdentifier('name')
+                ->add('slug')
+                ->add('enabled')
+            ;
+        }
+
+        /**
+         * @param \Sonata\AdminBundle\Validator\ErrorElement $errorElement
+         * @param $object
+         * @return void
+         */
+        public function validate(ErrorElement $errorElement, $object)
+        {
+            $errorElement
+                ->with('name')
+                    ->assertMaxLength(array('limit' => 32))
+                ->end()
+            ;
+        }
     }
 
 Tweak the CommentAdmin class
@@ -243,34 +235,77 @@ Tweak the CommentAdmin class
     use Sonata\AdminBundle\Datagrid\DatagridMapper;
     use Sonata\AdminBundle\Datagrid\ListMapper;
 
-    use Sonata\NewsBundle\Entity\Comment;
+    use Application\Sonata\NewsBundle\Entity\Comment;
 
     class CommentAdmin extends Admin
     {
-        protected $list = array(
-            'name' => array('identifier' => true),
-            'getStatusCode' => array('label' => 'status_code', 'type' => 'string', 'sortable' => 'status'),
-            'post',
-            'email',
-            'url',
-            'message',
-        );
-
-        protected $form = array(
-            'name',
-            'email',
-            'url',
-            'message',
-        );
-
-        protected $filter = array(
-            'name',
-            'email',
-            'message'
-        );
-
-        protected function configureFormFields(FormMapper $form)
+        protected $parentAssociationMapping = 'post';
+
+        /**
+         * @param \Sonata\AdminBundle\Form\FormMapper $formMapper
+         * @return void
+         */
+        protected function configureFormFields(FormMapper $formMapper)
         {
-            $form->add('status', array('choices' => Comment::getStatusList()), array('type' => 'choice'));
+            if(!$this->isChild()) {
+                $formMapper->add('post', 'sonata_type_model', array(), array('edit' => 'list'));
+    //            $formMapper->add('post', 'sonata_type_admin', array(), array('edit' => 'inline'));
+            }
+
+            $formMapper
+                ->add('name')
+                ->add('email')
+                ->add('url', null, array('required' => false))
+                ->add('message')
+                ->add('status', 'choice', array('choices' => Comment::getStatusList(), 'expanded' => true, 'multiple' => false))
+            ;
+        }
+
+        /**
+         * @param \Sonata\AdminBundle\Datagrid\DatagridMapper $datagridMapper
+         * @return void
+         */
+        protected function configureDatagridFilters(DatagridMapper $datagridMapper)
+        {
+            $datagridMapper
+                ->add('name')
+                ->add('email')
+                ->add('message')
+            ;
+        }
+
+        /**
+         * @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
+         * @return void
+         */
+        protected function configureListFields(ListMapper $listMapper)
+        {
+            $listMapper
+                ->addIdentifier('name')
+                ->add('getStatusCode', 'text', array('label' => 'status_code', 'sortable' => 'status'))
+                ->add('post')
+                ->add('email')
+                ->add('url')
+                ->add('message');
+        }
+
+        /**
+         * @return array
+         */
+        public function getBatchActions()
+        {
+            $actions = parent::getBatchActions();
+
+            $actions['enabled'] = array(
+                'label' => $this->trans('batch_enable_comments'),
+                'ask_confirmation' => false,
+            );
+
+            $actions['disabled'] = array(
+                'label' => $this->trans('batch_disable_comments'),
+                'ask_confirmation' => false
+            );
+
+            return $actions;
         }
     }