list_field_definition.rst 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 list fields are defined by overriding the ``list`` property
  25. and giving each definition an array of options. You can also customize each
  26. field further by overriding the ``configureListFields()`` method, which is
  27. 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. * date
  41. If no type is set, the ``Admin`` class will use the type defined in the doctrine
  42. mapping definition.
  43. List Actions
  44. ------------
  45. You can set actions for each items in list by adding in $list, the '_action' field :
  46. .. code-block:: php
  47. '_action' => array(
  48. 'actions' => array(
  49. 'delete' => array(),
  50. 'edit' => array()
  51. )
  52. )
  53. Edit and delete actions are available in default configuration. You can add your own! Default template file is :
  54. SonataAdminBundle:CRUD:list__action_[ACTION_NAME].html.twig
  55. But you can specify yours by setup 'template' option like :
  56. .. code-block:: php
  57. '_action' => array(
  58. 'actions' => array(
  59. 'delete' => array('template' => 'MyBundle:MyController:my_partial.html.twig'),
  60. 'edit' => array()
  61. )
  62. )
  63. Tweak it!
  64. ---------
  65. It is possible to change the default template by setting a template key in the
  66. definition.
  67. - if the identifier key is set, then the field will be encapsulate by a link to
  68. the edit action