Jelajahi Sumber

Documentation for sub model properties.

Romain Geissler 13 tahun lalu
induk
melakukan
f74270f428

+ 34 - 0
Resources/doc/reference/filter_field_definition.rst

@@ -68,6 +68,40 @@ Example
 Advanced usage
 --------------
 
+Filtering by sub entity properties
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+If you need to filter your base entities by the value of a sub entity property,
+you can simply use the dot-separated notation (note that this only makes sense
+when the prefix path is made of entities, not collections):
+
+.. code-block:: php
+
+    <?php
+    namespace Acme\AcmeBundle\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 UserAdmin extends Admin
+    {
+        protected function configureDatagridFilters(DatagridMapper $datagrid)
+        {
+            $datagrid
+                ->add('id')
+                ->add('firstName')
+                ->add('lastName')
+                ->add('address.street')
+                ->add('address.ZIPCode')
+                ->add('address.town')
+            ;
+        }
+    }
+
+
 Label
 ^^^^^
 

+ 37 - 0
Resources/doc/reference/list_field_definition.rst

@@ -93,6 +93,43 @@ You can specify your own by setting up the 'template' option like so:
 Advance Usage
 -------------
 
+Displaying sub entity properties
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+If you need to display only one field from a sub entity in a dedicated column,
+you can simply use the dot-separated notation (note that this only makes sense
+when the prefix path is made of entities, not collections):
+
+.. code-block:: php
+
+    <?php
+    namespace Acme\AcmeBundle\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 UserAdmin extends Admin
+    {
+        protected function configureListFields(ListMapper $listMapper)
+        {
+            $listMapper
+                ->addIdentifier('id')
+                ->addIdentifier('firstName')
+                ->addIdentifier('lastName')
+                ->addIdentifier('address.street')
+                ->addIdentifier('address.ZIPCode')
+                ->addIdentifier('address.town')
+            ;
+        }
+    }
+
+
+Custom template
+^^^^^^^^^^^^^^^
+
 If you need a specific layout for a row cell, you can define a custom template
 
 .. code-block:: php