list_field_definition.rst 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. List field definition
  2. =====================
  3. These fields are used to display the information inside the list table.
  4. Example
  5. -------
  6. .. code-block:: php
  7. <?php
  8. namespace Sonata\NewsBundle\Admin;
  9. use Sonata\AdminBundle\Admin\Admin;
  10. use Sonata\AdminBundle\Datagrid\ListMapper;
  11. class PostAdmin extends Admin
  12. {
  13. protected $list = array(
  14. 'title' => array(),
  15. 'enabled' => array('type' => 'boolean'),
  16. 'tags' => array(),
  17. 'summary' => array()
  18. );
  19. protected function configureListFields(ListMapper $list) // optional
  20. {
  21. $list->get('summary')->setTemplate('NewsBundle:NewsAdmin:list_summary.twig');
  22. }
  23. }
  24. As you can see, the filter fields are defined by overriding the ``filter_fields``
  25. property and giving each definition an array of options. You can also customize
  26. each field further by overriding the ``configureListFields()`` method, which
  27. is blank in the parent class.
  28. Types available
  29. ---------------
  30. The most important option for each field is the ``type``: The available
  31. types include:
  32. * boolean
  33. * datetime
  34. * decimal
  35. * identifier
  36. * integer
  37. * many_to_one : a link will be added to the related edit action
  38. * string
  39. * text
  40. If no type is set, the ``Admin`` class will use the type defined in the doctrine
  41. mapping definition.
  42. List Actions
  43. ------------
  44. You can set actions for each items in list by adding in $list, the '_action' field :
  45. .. code-block:: php
  46. '_action' => array(
  47. 'actions' => array(
  48. '_delete' => array(),
  49. '_edit' => array()
  50. )
  51. )
  52. Edit and delete actions are available in default configuration. You can add your own! Default template file is :
  53. SonataAdminBundle:CRUD:list__action[ACTION_NAME].html.twig
  54. But you can specify yours by setup 'template' option like :
  55. .. code-block:: php
  56. '_action' => array(
  57. 'actions' => array(
  58. '_delete' => array('template' => 'MyBundle:MyController:my_partial.html.twig'),
  59. '_edit' => array()
  60. )
  61. )
  62. Tweak it!
  63. ---------
  64. It is possible to change the default template by setting a template key in the
  65. definition.
  66. - if the identifier key is set, then the field will be encapsulate by a link to
  67. the edit action