list_field_definition.rst 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. Tweak it!
  43. ---------
  44. It is possible to change the default template by setting a template key in the
  45. definition.
  46. - if the identifier key is set, then the field will be encapsulate by a link to
  47. the edit action