list_field_definition.rst 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 Bundle\NewsBundle\Admin;
  9. use Bundle\Sonata\BaseApplicationBundle\Admin\Admin;
  10. class PostAdmin extends Admin
  11. {
  12. protected $class = 'Application\Sonata\NewsBundle\Entity\Post';
  13. protected $list_fields = array(
  14. 'title' => array(),
  15. 'enabled' => array('type' => 'boolean'),
  16. 'tags' => array()
  17. );
  18. public function configureListFields() // optional
  19. {
  20. $this->list_fields['summary']['template'] = 'NewsBundle:NewsAdmin:list_summary.twig';
  21. }
  22. }
  23. As you can see, the filter fields are defined by overriding the ``filter_fields``
  24. property and giving each definition an array of options. You can also customize
  25. each field further by overriding the ``configureListFields()`` method, which
  26. is blank in the parent class.
  27. Types available
  28. ---------------
  29. The most important option for each field is the ``type``: The available
  30. types include:
  31. * boolean
  32. * datetime
  33. * decimal
  34. * identifier
  35. * integer
  36. * many_to_one : a link will be added to the related edit action
  37. * string
  38. * text
  39. If no type is set, the ``Admin`` class will use the type defined in the doctrine
  40. mapping definition.
  41. Tweak it!
  42. ---------
  43. It is possible to change the default template by setting a template key in the
  44. definition.
  45. - if the identifier key is set, then the field will be encapsulate by a link to
  46. the edit action